On 7 Jul 2005 21:24:45 -0700,
ju**********@yahoo.co.in wrote:
Where does the storage is allocated for the various argument
strings (char *argv[]) passed to the main() ?
In main() we never allocate space for these. So, which function
does it and how does it know how much space to allocate ?
It's up to the implementation; the only requirement in the Standard is
that they be writable (within their supplied lengths). Note this is
the string contents argv[*][*]; the string pointers argv[*] aren't
guaranteed writable, although they usually are. The top pointer argv
is a parameter of main() and thus writable if not declared const,
which I think it can be (they're certainly compatible for functions in
general, although 5.1.2.2.1 doesn't actually say 'compatible').
In most implementations the command-line data, either as a line or as
tokens, is supplied by the operating system, so the C runtime has to
get it, somehow, into some space, somewhere, before entering main().
The traditional Unix implementation is for the OS to provide packed
tokens at the base of the stack (where base = high address and top =
low address because the stack grows downward).
Implementations on odder OS'es or no OS will be different.
- David.Thompson1 at worldnet.att.net