"Aaron Ardiri" wrote: > > > > char *sdf; > > > sdf = "ABC";
[ ... snip ...] > va? the first one wont even work :) Er, what? Sure it works. Create a constant string literal "ABC". The compiler stores it where all other string literals go. At run-time, create a stack frame for sdf, and assign sdf to point to that string literal. Compiles fine for me with gcc, with all warnings on and even using pedantic mode. =P On the other hand: char sdf[]; sdf = "ABC"; is quite wrong and will generate compile-time errors. > 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. It doesn't need to allocate storage for the data at run-time because "ABC" is stored statically. > > > char sdf[] = "ABC"; > > the second case does these steps in one. however, the "ABC" string is > stored on the stack, not the dynamic heap. I never said nor meant to imply that either case involved the dynamic heap. My point was that declaring sdf as type array-of-char rather than of type pointer-to-char for the sake of "saving space for the pointer" is pointless (no pun intended). -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
