简体   繁体   English

C编译错误

[英]C Compile Errors

I'm currently working on an assignment where a ListNode struct is created that contains the pointer to the next ListNode in the linked list, and a pointer to the Info struct where the information is stored about the node. 我当前正在处理一个分配,其中创建一个ListNode结构,该结构包含指向链表中下一个ListNode的指针,以及一个指向存储有关该节点的信息的Info结构的指针。

I currently have the following code: 我目前有以下代码:

info.h info.h

#ifndef info
#define info

//Define the node structure
typedef struct Info {
    size_t pos;
    size_t size;
} Info_t;

#endif

listNode.h listNode.h

#ifndef listNode
#define listNode

//Define the node structure
typedef struct ListNode {
    struct Info_t *info;
    struct ListNode *next;
} ListNode_t;

ListNode_t* newListNode(ListNode_t* next, Info_t* info);

void destroyListNode(ListNode_t* node);

#endif

listNode.c listNode.c

#include <stdio.h>
#include <stdlib.h>
#include "info.h"
#include "listNode.h"

ListNode_t* newListNode(ListNode_t* next, Info_t* info)
{
    //Set the current node to the head of the linked list
    ListNode_t *current = next;

    //Move to the next node as long as there is one. We will eventually get to the end of the list
    while (current->next != NULL) {
        current = current->next;
    }

    //Create a new node and initialise the values
    current->next = malloc(sizeof(ListNode_t));
    current->next->info = info;

    return current;
}

void destroyListNode(ListNode_t* node)
{

}

when I attempt to compile this I get the following errors and cannot for the life of me figure out where this is going wrong. 当我尝试编译此错误时,出现以下错误,并且终生无法找出错误所在。

gcc -g -Wall listNode.c -o listNode

In file included from listNode.c:7:0:
listNode.h:9:24: error: expected identifier or ‘(’ before ‘;’ token
     struct Info_t *info;
                        ^
listNode.c: In function ‘newListNode’:
listNode.c:9:1: error: parameter name omitted
 ListNode_t* newListNode(ListNode_t* next, Info_t* info)
 ^~~~~~~~~~
listNode.c:21:25: error: expected identifier before ‘=’ token
     current->next->info = info;
                         ^

Any help would be greatly appreciated. 任何帮助将不胜感激。

The name of your include guard is conflicting with an identifier that you're using in the program. 您的包含保护的名称与您在程序中使用的标识符冲突。 You define info here: 您在此处定义info

#define info

Specifically, you define it as nothing. 具体来说,您将其定义为空。 So this here 所以这里

current->next->info = info;

Turns into this: 变成这样:

current->next->= ;

And struct Info_t *info; struct Info_t *info; turns into struct Info_t *; 变成struct Info_t *; . Those obviously won't compile. 那些显然不会编译。 You need to rename the info in your include guards to something that won't conflict with anything else, such as INFO_H_GUARD . 您需要将包含保护中的info重命名为不会与其他任何内容冲突的内容,例如INFO_H_GUARD

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM