简体   繁体   English

错误:在“*”标记结构之前应有“{”(C 编程帮助)

[英]error: expected ‘{’ before ‘*’ token struct (C programming help)

I am getting the following error when I try to compile and run my code.尝试编译和运行代码时出现以下错误。 " error: expected '{' before '*' token struct ". “错误:在'*'令牌结构之前预期'{'”。

    The code it is referring to:

    #ifndef node
    #define node
    struct node
    {
     int datum;
     struct node * next;
    }  ;
   #endif

The above code is for a user-defined header file called "node.h".上面的代码是一个名为“node.h”的用户定义的 header 文件。 It will be used to create a linked list.它将用于创建链接列表。

#define node

That will replace with an empty token wherever there is a node after that point.在该点之后有node的任何地方都将替换为空令牌。 So after preprocessing the code becomes:所以预处理后的代码变成:

struct
{
 int datum;
 struct * next;
}  ;

So need to pick a name for the define that is not used as an identifier in the file.所以需要为在文件中不用作标识符的define选择一个名称。 Commonly the define reflects the file name:通常定义反映文件名:

#ifndef NODE_H
#define NODE_H

struct node
{
    int datum;
    struct node * next;
};

#endif 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 指向C中的结构-错误:“ *”标记之前的预期“)” - Pointing to struct in C - error: expected ')' before '*' token C Global Struct:“错误:'{'令牌之前的预期表达式” - C Global Struct: “error: expected expression before '{' token” C-创建和使用结构数组? 错误:预期标识符或'['标记前的'(' - C - Creating and using an struct array? error: expected identifier or '(' before '[' token 错误:结构中'='标记之前的预期':',',',';','}'或'__attribute__' - error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘=’ token in struct C错误:在'='标记前应为';',','或')' - C -error: expected ';', ',' or ')' before '=' token C:错误:预期')'之前';' 代币 - C: error: expected ')' before ';' token C错误:在'...'标记之前预期';',','或')' - C error: expected ';', ',' or ')' before '…' token C中“ *”令牌错误之前的预期“)” - expected ')' before '*' token error in c 错误:预期的 ',' 或 ';' C 编程中的“文件”之前 - error: expected ',' or ';' before 'FILE' in C Programming C 编程错误:“移动”之前应为“(” - C programming error: expected '(' before 'move'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM