Thanks to everyone who offered answers to my question. It's starting to make
sense now.  Hope you don't mind if I dig a little further. 

If I understand correctly, char s1[]= "Hello"; puts that array of characters
(plus the NULL) on the stack. Could I then  execute something like
printf("%s", s1) and have it print Hello?  If true, when that printf runs,
how does it know which bytes to pull off the stack.  I might have added
additional things to the stack, so how does it know where to find it if
there is no pointer to it? If I could understand that, I'd really be getting
somewhere.  Thanks.

Mitch

> -----Original Message-----
> From: Greg Winton [SMTP:[EMAIL PROTECTED]]
> Sent: Wednesday, March 10, 1999 12:48 PM
> To:   [EMAIL PROTECTED]
> Subject:      Re: Variable storage question
> 
> At 12:18 PM 3/10/99 -0500, you wrote:
> >> char s1[]= "Hello";   // array of characters
> >> CharPtr  s2;      // pointer to a string
> >> char s3[20];    // array of 20 caharacters
> >> CharPtr s4[10];    // array of 10 pointers
> >> int i;    // integer
> >> int j[10];    // array of 10 integers
> >>
> >> s2 = "Goodbye";
> >> i = 15;
> >>
> >
> >      In your example, s, s2, s3, s4, i, and j are all on the stack
> (total
> >usage 92 bytes, assuming ints are 2 bytes), and where that constant
> string
> >lives depends on your compiler settings.  I'll let the compiler jockeys
> >figure out where that one goes - it's probably in your global data, which
> I
> >think is on the heap, but don't quote me.  If you wanted to allocate one
> of
> >your arrays on the heap, you'd declare it as a pointer and use MemPtrNew
> to
> >allocate it.
> >
> 
> I'm no compiler jockey, but the declaration for s1 will allocate 6 bytes
> on
> the stack, and initialize it to "Hello\0".  This is because you declared
> it
> as a non-const array.
> 
> const char s1[] = "Hello";
> 
> would have generated 6 bytes for the string "Hello" and 4 bytes for the
> pointers (s1 and sP) to these strings.  
> 
> Hope this helps.
> 
> Regards,
> Greg
> 
> Greg Winton
> Bachmann Software and Services, LLC
> mailto:[EMAIL PROTECTED]
> http://www.bachmannsoftware.com
> Software Development for Handheld & Mobile Computing, Windows and the
> Internet
> Home of Bachmann Print Manager, the only graphical printing solution for
> the Palm Computing Platform
> 

Reply via email to