Thread: argv confusion

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    75

    argv confusion


    char **foo; /* a pointer to a pointer to char */
    char *bar[]; /* an array of pointers to char, of unspecified size */

    *argv[] is nothing more than syntactic
    sugar for **argv (Note that this discussion is valid only for argv when used as function
    parameter. )
    I don't understand why *argv[] and **argv have the same meaning when used as a fct parameter.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    An array is converted to a pointer to its first element when it is passed as an argument. A simpler example:
    Code:
    void print_numbers(int numbers[]);
    is equivalent to:
    Code:
    void print_numbers(int *numbers);
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Because they mean exactly the same thing. You can't pass arrays. It's an illusion. You always pass a pointer to the first element instead. So the two syntaxes mean the same thing, but are typed differently.
    Code:
    void foo(int* numbers[]);
    is also equivalent to:
    Code:
    void foo(int** numbers);
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. argv
    By taurus in forum C Programming
    Replies: 15
    Last Post: 10-14-2007, 08:57 AM
  2. Using argc and argv data
    By Rad_Turnip in forum C Programming
    Replies: 4
    Last Post: 03-31-2006, 06:09 AM
  3. Converting a argc / argv construct into a va_list
    By chambece in forum C Programming
    Replies: 6
    Last Post: 07-03-2005, 04:47 PM
  4. how do i? re: argc - argv
    By luigi40 in forum C Programming
    Replies: 2
    Last Post: 06-11-2004, 10:17 AM
  5. more argv and argc
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 09-08-2001, 11:04 PM