GCC likes to tell me that I'm missing a specifier-qualifier-list in its error messages.
I know that this means I didn't put in a correct type of something.
But what exactly is a specifier-qualifier-list?
Edit:
Example C code that causes this:
#include <stdio.h>
int main(int argc, char **argv) {
struct { undefined_type *foo; } bar;
printf("Hello, world!");
}
Gives these errors from GCC:
Lappy:code chpwn$ gcc test.c
test.c: In function ‘main’:
test.c:4: error: expected specifier-qualifier-list before ‘undefined_type’
A qualifier is a keyword which modifies a specifier. In C and C++, this is mostly seen with types. Consider a type specifier of const int . Here, int is a type specifier. const is the qualifier for the type specifier.
The “expected specifier-qualifier-list before…” error occurs in C/C++ when the compiler cannot figure out a data structure or a variable's type. Consider the common error scenario shown in the code snippet below: 10. 1. typedef struct.
It's a list of specifiers and qualifiers :-) Specifiers are things like void
, char
, struct Foo
, etc., and qualifiers are keywords like const
and volatile
. See this C grammar for the definition.
In your case, undefined_type
was not defined yet, so the parser saw it as an identifier, not a specifier-qualifier-list like it expected. If you were to typedef ... undefined_type;
before its occurrence, then undefined_type
would become a specifier.
If you think in terms of parsing C with a context-free grammar, the way the compiler handles typedefs and such may be bothersome. If I understand correctly, it games the parser generator by sneaking in symbol table operations so it can use context to parse the source code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With