Re: Difference between argc and argv?

From: Greg Comeau (comeau_at_panix.com)
Date: 03/01/04


Date: 1 Mar 2004 09:20:40 -0500

In article <icf640l5k0g7g85k1sctkh2udukiilf8s9@4ax.com>,
Gawnsoft <xlucid@users.sourceforge.remove.this.antispam.net> wrote:
>On Sat, 28 Feb 2004 20:09:58 GMT, "Mike Wahler"
><mkwahler@mkwahler.net> wrote (more or less):
>>[main()s] paramters, typically named
>>'argc' and 'argv'...specify the number of arguments passed, and
>>a pointer to an array of strings representing the actual
>>arguments.....
>
>What's the difference between argc and argv?

Here's what Standard C says:

"... two parameters (referred to here as argc and argv, though
any names may be used, as they are local to the function in which
they are declared):

  int main(int argc, char *argv[]) { /* ... */ }

or equivalent;9) or in some other implementation-defined manner.

If they are declared, the parameters to the main function shall
obey the following constraints:

* The value of argc shall be nonnegative.
* argv[argc] shall be a null pointer.
* If the value of argc is greater than zero, the array members
  argv[0] through argv[argc-1] inclusive shall contain pointers
  to strings, which are given implementation-defined values by the
  host environment prior to program startup. The intent is to
  supply to the program information determined prior to
  program startup from elsewhere in the hosted environment.
  If the host environment is not capable of supplying strings with
  letters in both uppercase and lowercase, the implementation
  shall ensure that the strings are received in lowercase.
* If the value of argc is greater than zero, the string pointed to
  by argv[0] represents the program name; argv[0][0] shall be
  the null character if the program name is not available from the
  host environment. If the value of argc is greater than one,
  the strings pointed to by argv[1] through argv[argc-1]
  represent the program parameters.
* The parameters argc and argv and the strings pointed to by the
  argv array shall be modifiable by the program, and retain their
  last-stored values between program startup and program termination."

Feel free to post any questions about the above.

-- 
Greg Comeau / Comeau C++ 4.3.3, for C++03 core language support
Comeau C/C++ ONLINE ==>     http://www.comeaucomputing.com/tryitout
World Class Compilers:  Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?


Relevant Pages

  • Re: two dimensional arrays passed to functions
    ... > array and then send it down as a single dimmensional array. ... x is an array of char pointers. ... to a pointer to the first element of this array, ... need to copy the strings and not just assign pointers to them). ...
    (comp.lang.c)
  • Re: low-level pointer vs. array question
    ... that the array version is indeed superiour for my purposes. ... memory for pointer variables. ... Note that "it allocates memory only for the strings" ...
    (comp.lang.c)
  • Re: fast stable sort
    ... rather than isolating it in a separate array. ... It lumps an extra pointer in with the only one ... Building a linked list does not constitute using Oextra space. ... strings and linking the strings into an order. ...
    (comp.programming)
  • Re: char *arr[n] Vs. char **arr
    ... since the number of small strings is not ... the array format[], and copy the token to that address. ... The malloc statement gives a segfault. ... makes an integer from pointer" etc.. ...
    (comp.lang.c)
  • Re: char *arr[n] Vs. char **arr
    ... since the number of small strings is not ... the array format[], and copy the token to that address. ... The malloc statement gives a segfault. ... makes an integer from pointer" etc.. ...
    (comp.lang.c)