代码之家  ›  专栏  ›  技术社区  ›  Grant Paul

什么是说明符限定符列表?

  •  5
  • Grant Paul  · 技术社区  · 16 年前

    GCC喜欢告诉我在它的错误消息中缺少一个说明符限定符列表。

    我知道这意味着我没有输入正确的类型。

    但到底是什么 说明符限定符列表?

    编辑:

    导致这种情况的示例C代码:

    #include <stdio.h>
    
    int main(int argc, char **argv) {
        struct { undefined_type *foo; } bar;
        printf("Hello, world!");
    }
    

    给出了GCC的这些错误:

    Lappy:code chpwn$ gcc test.c
    test.c: In function ‘main’:
    test.c:4: error: expected specifier-qualifier-list before ‘undefined_type’
    
    1 回复  |  直到 14 年前
        1
  •  5
  •   Joey Adams    14 年前

    它是一个说明符和限定符的列表:-)说明符类似于 void , char , struct Foo 等等,限定符是关键字,比如 const volatile . 见 this C grammar 对于定义。

    在你的情况下, undefined_type 尚未定义,因此分析器将其视为标识符,而不是预期的说明符限定符列表。如果你愿意 typedef ... undefined_type; 在它发生之前,那么 未定义类型 将成为说明符。

    如果您认为用上下文无关语法解析C,编译器处理typedef的方式可能会很麻烦。如果我理解正确,它通过潜入符号表操作来模拟解析器生成器,这样它就可以使用上下文来解析源代码。