HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Char Buffer Initialization
Operating System - HP-UX
1833758
Members
2380
Online
110063
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2003 06:52 AM
07-24-2003 06:52 AM
Good Morning:
I am working gcc 64, for HP11.11. I am migrating a program, and I find several run problems in the handle of variables declared as char pointer:
char *buffer;
Exist in gcc any compile option for initialize the buffer when is declared: I means, when find the instruction
char *buffer;
autmatically put in buffer[0]='\0'
Thanks a lot for any help.
I am working gcc 64, for HP11.11. I am migrating a program, and I find several run problems in the handle of variables declared as char pointer:
char *buffer;
Exist in gcc any compile option for initialize the buffer when is declared: I means, when find the instruction
char *buffer;
autmatically put in buffer[0]='\0'
Thanks a lot for any help.
alfonsoarias
Solved! Go to Solution.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2003 07:04 AM
07-24-2003 07:04 AM
Solution
No and this is absolutely not a good idea. At best, it would be code that is not portable.
You could, of course,
char *buffer = {""};
to do this but this is of limited value because all you have done is created a 1-byte string to hold the NUL. If you stop to think for a moment you will realize that your request really doesn't make a lot of sense because no intelligent space allocation can be done. I suspect that you are testing the string for length 0 and if so then allocating space. A better way is this (which will be completely portable):
char *buffer = NULL;
if (buffer == NULL)
{
buffer = (char *) malloc((size_t) (nbytes + 1));
}
You could, of course,
char *buffer = {""};
to do this but this is of limited value because all you have done is created a 1-byte string to hold the NUL. If you stop to think for a moment you will realize that your request really doesn't make a lot of sense because no intelligent space allocation can be done. I suspect that you are testing the string for length 0 and if so then allocating space. A better way is this (which will be completely portable):
char *buffer = NULL;
if (buffer == NULL)
{
buffer = (char *) malloc((size_t) (nbytes + 1));
}
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2003 07:57 AM
07-24-2003 07:57 AM
Re: Char Buffer Initialization
Thanks Clay. Now is clear for me.
alfonsoarias
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP