Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a specifier-qualifier-list?

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’
like image 443
Grant Paul Avatar asked May 24 '10 03:05

Grant Paul


People also ask

What is specifier qualifier?

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.

What is specifier qualifier in C?

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.


1 Answers

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.

like image 120
Joey Adams Avatar answered Sep 25 '22 15:09

Joey Adams