473,320 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

storage for argv

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 ?

Thanx for any help ...

Nov 15 '05 #1
3 1994
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 ?

Thanx for any help ...


It depends on your system. On my system, there is a startup function
that creates the "environment" main() will run in but you probably
weren't asking about an IBM mainframe.
<<Remove the del for email>>
Nov 15 '05 #2
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 ?

Thanx for any help ...


It's none of your business! :-)
Seriously, it isn't. When your program is loaded by the OS, the CRT (C
Run Time) for your program gets executed. It is the CRT that creates the
sandbox that your program will play in. That includes building the input
data structure 'char argv[]'. Only then does CRT call your 'main()'.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 15 '05 #3
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
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Robin Sanderson | last post by:
Sorry in advance if this is a stupid question - I am new to C++. In the process of converting program to be run from the command line into a function to be run from another program I noticed...
28
by: Charles Sullivan | last post by:
I'm working on a program which has a "tree" of command line arguments, i.e., myprogram level1 ]] such that there can be more than one level2 argument for each level1 argument and more than one...
22
by: Joe Smith | last post by:
It is nothing short of embarrassing to feel the need to ask for help on this. I can't see how I would make the main control for this. What I want is a for loop and a test condition. And while I...
74
by: aruna.mysore | last post by:
Hi all, I have a simple definitioin in a C file something like this. main() { char a; ....... int k; }
9
by: jmcgill | last post by:
Saw this used as an example. Compiles without warnings. "Works." Kosher or not? Why or why not? #include <stdio.h> int main(int argc, char **argv){ int i,j,k,l,m; int *p; i=2; j=4; k=8;...
5
by: Ivan Novick | last post by:
Is the string below automatic storage duration? #include <iostream> #include <string> int main(int argc, char** argv) { std::cout << std::string().size() << std::endl; return 0; }
4
by: interec | last post by:
Hi Folks, I am writing a c++ program on redhat linux using main(int argc, wchar_t *argv). $LANG on console is set to "en_US.UTF-8". g++ compiler version is 3.4.6. Q1. what is the encoding of...
3
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I get a strange compile error when compile such simple program. Any ideas? foo.c: In function `main': foo.c:5: error: storage size of 'var' isn't known foo.c
8
by: junky_fellow | last post by:
Guys, Consider the following snippet of code: int main(VOID) { static ushort fractionalValue={ 0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 250, 333, 666, 750, 0, 0 };
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.