C gcc 预期为 '=' 、 ',' 、 ';' 、 'asm' 或 '_attribute__' 之前

标签 c gcc

我对 C 中的结构非常陌生,我正在尝试使用几个结构和一个主 .c 文件编写一个程序。我正在尝试在结构中创建一个 Create,该结构返回一个指向该结构的指针,供我的主文件处理。

但是,每次我都会收到以下错误: 在“createCust”之前应有“=”、“,”、“;”、“asm”或“_attribute__” Customer createCust(...) {(克拉位于 createCust 的开头)。

以下是相关代码片段: 客户.h

#ifndef CUSTOMER_H
#define CUSTOMER_H
#include "order.h"

typedef struct customer *Customer;

Customer createCust(...);
void addOrder(...);

#endif

还有 customer.c:

#include "customer.h"
#include "order.h"
#include <stdio.h>
#include <string.h>

Customer createCust(...);

struct customer {
    int customerNum;
    char name[20];
    order orders[20];
    int index;
    int capacity;
}

Customer createCust(int id, char nam[]) {
    Customer c = malloc(sizeof(struct customer));

    // other stuff

    return c;
}

尽管我的文件中包含了 order.h,但我还收到另一个关于 order 为何是未知类型的错误。

#ifndef ORDER_H
#define ORDER_H

typedef struct order *Order;

Order create(...);
#endif

最佳答案

结构体声明末尾缺少一个分号,即:

struct customer {
    int customerNum;
    char name[20];
    order orders[20];
    int index;
    int capacity;
};

关于C gcc 预期为 '=' 、 ',' 、 ';' 、 'asm' 或 '_attribute__' 之前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34035981/

相关文章:

C 套接字文件传输错误

c - Linux 中的 ^X 是什么?

c - -mtune=i486 和 -arch=i486 有什么区别

ios - 为 iOS 编译 C 源代码

c - mingw ld 找不到搜索路径中存在的某些库

c - azure-iot-sdk-c 交叉编译链接器问题 : ld: cannot find -luuid

c - arm cortex m4上的总线错误调试

c - mmap/mprotect-readonly 零页是否计入已提交内存?

c++ - OpenCV网络摄像头捕获问题

c - 位声明 - 对 'variable' 的 undefined reference