Re: The type of argv in K&R2



Joe Wright said:

Richard Heathfield wrote:
candide said:

Hi,

K&R2 §5.10 tells that the second parameter to the main function,
usually called argv, has type pointer to character strings.

I don't think it says so in exactly those words (and if it does, I'd
argue that it's wrong). Certainly I can't find such wording on a cursory
look through that section.

Okay, here's the whole thing.

There exists an array of char *. Zero (or more, but exactly argc)
members of that array each point to the first character of a string that
represents a command line argument. The next member, the [argc] member,
is guaranteed to be NULL.

Surely there are argc+1 members.

Right. Where did I say different?

Allow me to translate:

There exists an array of char *. Zero (or more, but exactly argc)
members of that array each point to the first character of a string that
represents a command line argument. The next member, the [argc] member,
is guaranteed to be NULL.

Get it now? :-)

Given argc == 2, argv[2] is the third
(and last) pointer in the array (and a NULL pointer).

Right. So exactly argc of them point to the first character of a string
that represents a command line argument (and I suppose I should clarify
that I am counting the program name - or some representation thereof - as
a command line argument), and the argv[argc]th member, argv[2] in your
example, is a null pointer. If that isn't broadly what I said the first
time, please point out the discrepancy.

<snip>

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
.



Relevant Pages

  • Re: Truncation of fractions in floating-point literals
    ... I will refer to the ISO C which is the same as the ISO C++ in the ... the string is in 932 DBCS and the backslash is a trailing char - not a leading one. ... Each source character ... converted to the corresponding member of the execution character set; ...
    (microsoft.public.dotnet.languages.vc)
  • Re: The type of argv in K&R2
    ... "has type pointer to array of character strings." ... character strings that contain the arguments, ...
    (comp.lang.c)
  • Re: I think argv[i] should give us a pointer value. Why it is given the value pointed by pointer
    ... Whereas I am expecting a pointer value. ... char *argvis an array of strings. ... Since a string in C is implemented ... shorthand for pointing to the first character of a string. ...
    (comp.lang.c)
  • Re: Initialising a pointer
    ... The value stored in this particular pointer is the address ... first character of a string literal. ... storing its result in a local pointer, and that then does some initial ...
    (comp.lang.c)
  • Re: The type of argv in K&R2
    ... has type pointer to character strings. ... members of that array each point to the first character of a string that ... The next member, the member, ...
    (comp.lang.c)