Is the following a standard C function declaration according to ISO/IEC 9899:2017 (c17)?
int foo(int (bar), int (baz));
If so, please point me to the section in the standard that defines this.
In N2310 Appendix Phrase structure grammar, A.2.2 Declarations, Section 6.7.6, I see the following:
parameter-list:
parameter-declaration
parameter-list , parameter-declaration
I'm not familiar with this type of grammar expression, so I'm not sure how to interpret it.
The following program compiles without errors with gcc --std=c17 -Wall
and clang --std=c17 -Wall
static int foo(int (bar), int (baz));
static int foo(int bar, int baz)
{
return bar + baz;
}
int main() {
return foo(1, 2);
}
However if I run cppcheck
(a static analysis tool) on this program, it appears to parse incorrectly.
I'm most interested if this grammar is standard C, or a compiler-specific behavior so I can try to fix the parser or submit a bug report if I can't.
int (*a)[5]
(a pointer to an array) is not the same asint *a[5]
(an array of pointers) – Stellecppcheck
-- It's hard for me to put much faith in a program that seems to think there is a language named "C/C++". I would be inclined to wonder what it does with code that is valid in one those two distinct languages but not in the other. Or with code that is valid in both but means different things in the two. – Causeint (x);
for plain variables is also allowed. As isint (x) = (1);
. As isint (x)={1};
. As isint (x)={(1)};
. C is not always a very rational language. – Saponaceous