C语言 之前的预期说明符限定符列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3888569/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 06:37:45  来源:igfitidea点击:

expected specifier-qualifier-list before

c

提问by Delan Azabani

I have this struct type definition:

我有这个结构类型定义:

typedef struct {
    char *key;
    long canTag;
    long canSet;
    long allowMultiple;
    confType *next;
} confType;

When compiling, gcc throws this error:

编译时,gcc 抛出这个错误:

conf.c:6: error: expected specifier-qualifier-list before ‘confType'

What does this mean? It doesn't seem related to other questions with this error.

这是什么意思?它似乎与此错误的其他问题无关。

回答by JoshD

You used confType before you declared it. (for next). Instead, try this:

您在声明之前使用了 confType。(下一个)。相反,试试这个:

typedef struct confType {
    char *key;
    long canTag;
    long canSet;
    long allowMultiple;
    struct confType *next;
} confType;

回答by schot

JoshD's answer now is correct, I usually go for an equivalent variant:

JoshD 现在的答案是正确的,我通常会选择等效的变体:

typedef struct confType confType;

struct confType {
    char *key;
    long canTag;
    long canSet;
    long allowMultiple;
    confType *next;
};

When you only want to expose opaque pointers, you put the typedefin your header file (interface) and the structdeclaration in your source file (implementation).

当您只想公开不透明的指针时,您可以将 放在typedef头文件(接口)中,并将struct声明放在源文件(实现)中。