Re: The type of argv in K&R2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joe Wright

    #1

    Re: The type of argv in K&R2

    candide wrote:
    Hi,
    >
    K&R2 §5.10 tells that the second parameter to the main function,
    usually called argv, has type pointer to character strings.
    >
    Some quotes from the book :
    >
    >
    -------------------- 8< ----------------------------------------
    "the second (argv, for argument vector) is a pointer to an array of
    character strings"
    >
    "Since argv is a pointer to an array of pointers,"
    >
    "Since argv is a pointer to the beginning of the array of argument strings"
    -------------------- >8 ----------------------------------------
    >
    >
    In fact, argv is rather an array of strings, as explained in the
    preceding § :
    >
    >
    -------------------- 8< ----------------------------------------
    "Compare the declaration and picture for an array of pointers:
    char *name[] = { "Illegal month", "Jan", "Feb", "Mar" };"
    -------------------- >8 ----------------------------------------
    >
    >
    Right ?
    >
    Thanks
    Nope. It is most correctly 'char **argv', pointer to pointer to char.
    Declaring 'char *argv[]' is exactly equivalent. It says argv is an array
    of pointers to char. Expressing argv as an array yields a pointer to its
    first element.

    I believe 'array of strings' is misleading. It is 'array of pointer to
    char' in fact.

    --
    Joe Wright
    "Everything should be made as simple as possible, but not simpler."
    --- Albert Einstein ---
  • CBFalconer

    #2
    Re: The type of argv in K&amp;R2

    Joe Wright wrote:
    >
    .... snip ...
    >
    Nope. It is most correctly 'char **argv', pointer to pointer to
    char. Declaring 'char *argv[]' is exactly equivalent. It says
    argv is an array of pointers to char. Expressing argv as an array
    yields a pointer to its first element.
    >
    I believe 'array of strings' is misleading. It is 'array of
    pointer to char' in fact.
    However those pointers have been initialized to point to arrays of
    char, and each array of char has been filled with a '\0' terminated
    string. The first pointer (the 0th) points to a string describing
    the running program iff that information is available else an empty
    string, and the argcth points to a NULL pointer, marking the end of
    the list.

    Note the difference between a pointer to an empty string (no data)
    and a NULL, which marks the list end.

    --
    [mail]: Chuck F (cbfalconer at maineline dot net)
    [page]: <http://cbfalconer.home .att.net>
    Try the download section.


    ** Posted from http://www.teranews.com **

    Comment

    • Barry Schwarz

      #3
      Re: The type of argv in K&amp;R2

      On Sun, 22 Jun 2008 20:44:35 -0400, CBFalconer <cbfalconer@yah oo.com>
      wrote:
      >Joe Wright wrote:
      >>
      >... snip ...
      >>
      >Nope. It is most correctly 'char **argv', pointer to pointer to
      >char. Declaring 'char *argv[]' is exactly equivalent. It says
      >argv is an array of pointers to char. Expressing argv as an array
      >yields a pointer to its first element.
      >>
      >I believe 'array of strings' is misleading. It is 'array of
      >pointer to char' in fact.
      >
      >However those pointers have been initialized to point to arrays of
      >char, and each array of char has been filled with a '\0' terminated
      >string. The first pointer (the 0th) points to a string describing
      >the running program iff that information is available else an empty
      >string, and the argcth points to a NULL pointer, marking the end of
      >the list.
      Of course you meant the argcth *is* a NULL pointer.
      >
      >Note the difference between a pointer to an empty string (no data)
      >and a NULL, which marks the list end.

      Remove del for email

      Comment

      Working...