Joe,

This is a generic C programming question.  It is not specific to Palm OS or its 
development tools, so you should probably post questions like this in a "how to 
program in C" forum.

In short, static structs (that is, those created as global variables or as statics 
local to a function) have their fields initialized to zero when the application 
starts.  Automatic structs (that is, those created as local variables) or structs 
allocated with malloc or MemPtrNew will have garbage in their fields.  It is up to you 
to initialize them to appropriate values after you've allocated the memory for them.

There is no supported method for determining if a pointer type contains a valid or 
invalid value.

-- Keith


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of joe
bloggs
Sent: Saturday, March 27, 2004 6:37 PM
To: Palm Developer Forum
Subject: Structure initialisation


Hello Forum,

When a structure is created, does anyone know if it's
elements are initialised? e.g. initegers set to 0 and
pointers/references set to NULL.

The reason I am asking is that my error handling code
deallocates memory by checking if mem pointers are not
NULL.  If structure elements are initialised, I can
check to see if memory has been allocated as follows:

if (someStruct.memPointer)
...

If structure elements are not initialised, can anyone
recommend a way to determine if a pointer is pointing
to allocated memory (instead of just garbage).

--
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to