views:

64

answers:

2

Take the following snippet:

 1  #include <stdio.h>
 2  #include <stdlib.h>
 3  int foo(char [6]);
 4
 5  int main(void) {
 6          char* bar="hello";
 7          return foo(bar);
 8  }
 9
10  int foo(char f[6]) {
11          return EXIT_SUCCESS;
12  }
13

What is the right technical term for "char [6]" on line 3? I call it "type and size specifier" which merely describes what its used for by the compiler.

The entire line 3 I use to call "call stack signature of the function" or simply "function signature". "function declaration" or "function prototype" would also be correct, as opposed to "function implementation".

Note: You don't need to explain me everything about call stacks, frames, calling conventions et. al. I'm only looking for the right terminology there. NOT the entire line 3, only how to call one single specifier, like "char [6]".

+3  A: 

In the C standard (ISO 9899:1999), this is a parameter type specifier and, if there is no identifier in that specifier, the parameter is said to be unnamed.

Any notion of "size" is part of the type (an array type with unknown size is said to be incomplete). Note that here, the [6] construction does not define an array type but a pointer type (top-level array declarators within parameter lists are automatically converted to pointer declarators, and the putative array size is ignored).

Thomas Pornin
Exactly the type of answer I was looking for. I'll try to chew it from all perspectives and eventually accept it. Thanks!
Flavius
+1  A: 

In the C grammar, the char [6] on line 3 is a parameter-type-list, consisting of a single parameter-list, which consists of a single parameter-declaration.

That parameter-declaration is made up of a declaration-specifier (char), and an abstract-declarator ([6]).

caf
Wow this is also a very nice explanation (and Thomas' one). I don't know which one to accept. I'd take them both!
Flavius
Question though: Is this grammar specified in the ISO standard or any other standard or did you use a compiler's parser.y as a reference? If the latter, which one?
Flavius
It's specified in Annex A of the standard. The latest online draft of the C99 standard can be found at http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1336.pdf.
John Bode