News for hackers. Stuff that matters.
Re:Resume in C by tcas on Tuesday March 17, 2015 @10:06AM (#9217967)

  char * argv
is a pointer to a string (or a single character).

  char ** argv
is a pointer to an array of pointers to strings. The latter is used since it allows for multiple arguments in (the number being `int argc`).

This picture shows the second example in terms of pointers:

http://www.londonquilters.org.uk/ctext/pic511.gif

Re:Resume in C by shultays on Tuesday March 17, 2015 @10:17AM (#9218046)
Wouldn't second simply segfault when you try to access it?
Re:Resume in C by tcas on Tuesday March 17, 2015 @12:32PM (#9219117)
Nope, neither will segfault on the initial access.

  char ** argv
is a null terminated array in C according to the C standard. (EDIT: see clarification below) C doesn't care about types at all and you can abuse this by casting pointers to different (sometimes incompatible types). The second argument to main (argv) it set up by the initialization code and has the same space as a pointer regardless if it's a string, array of strings, struct, integer etc...

The existing structure will simply be interpreted as that new type like so:

                String1       String2    String3     String4
  char ** a2: |0x41414141 |0x42424242 |0x43434343 |0x00000000 |
              +-----------+-----------+-----------+-----------+
  char * a1 : |41|41|41|41|42|42|42|42|43|43|43|43|00|00|00|00|
  
  printf("%s\n", a1);
  > AAAABBBBCCCC
That being said, some compilers (clang) will emit an error on the improper type, like so:

  test.c:3:5: error: second parameter of 'main' (argument array) must be of type
        'char **'
  int main(int argc, char * argv)
      ^
  1 error generated.
Re:Resume in C by pqomdv on Tuesday March 17, 2015 @12:49PM (#9219258)
We are talking about C and not a specific compiler, so there are a lot of mistakes in your comment.

char * * is a pointer to a pointer to a char and nothing else, it might be a NULL terminated array or not at all.

C cares about types. Casting a pointer to an incompatible type or reinterpreting through an incompatible pointer is not defined in C( undefined behavior ).

Pointers of different types are allowed to have different sizes. sizeof( char* ) == sizeof( char* * ) is not guaranteed in C.

Also any program whose main is not int main( void ) or int main( int , char* * ) will result in undefined behavior.

All of this is in the latest standard.

Both, segfaulting or running completely normally can be a result of undefined behavior. That is why we really like to avoid it in C. Thus your advice is really not good for a modern C.

Re:Resume in C by tcas on Tuesday March 17, 2015 @01:37PM (#9219702)
In the case of argv though on main it is defined to be null terminated on argv[argc] according to the standard. Assuming the pointers are the same size though what I said will work but is bad practice.

> sizeof( char* ) == sizeof( char* * )

True, I forgot that different architectures/compilers can produce different pointer sizes. Thanks!

Re:Resume in C by pqomdv on Tuesday March 17, 2015 @01:55PM (#9219859)
char* * argv is NULL terminated, my mistake I though you were referring to that type in general.