> > Actually, that part of the code is valid: > > > > char *sdf; > > sdf = "ABC"; > > > > Four bytes of constant data have been allocated for "ABC", and sdf is > > set to point at that data. If sdf isn't going to change, then > > > > char sdf[] = "ABC"; > > > > is equivalent, and saves the space for the pointer. > > Do you really gain anything? In the first case, ignoring alignment > requirements, you consume sizeof (char*) bytes on the stack and four > bytes from wherever-it-is-string-literals-go. > > In the second case, you consume four bytes on the stack and four > bytes from wherever-it-is-the-array-initializer-gets-stored. > > The second case also requires more instructions to initialize the > sdf (although the first requires some for dereferencing...)
va? the first one wont even work :) > > char *sdf; > > sdf = "ABC"; the first one allocates a pointer to a char (4 bytes). it doesn't allocate any storage for the data. you will need to do a MemPtrNew() and copy the "ABC" string into it using StrCopy() or StrPrintF(). doing sdf = "ABC" wont do anything but give you errors. you will need to do a MemPtrFree() to clean up the memory your using as well. > > char sdf[] = "ABC"; the second case does these steps in one. however, the "ABC" string is stored on the stack, not the dynamic heap. --- Aaron Ardiri [EMAIL PROTECTED] CEO - CTO +46 70 656 1143 Mobile Wizardry http://www.mobilewizardry.com/ -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
