Error: Conflicting types in structs pointers

Error: Conflicting types in structs pointers

我正在尝试将固定结构转换为动态结构,但出现下一个错误:warning: data definition has no type or storage classwarning: type defaults to 'int' in declaration of 'clientes' [-Wimplicit-int]。我会展示我的项目:

文件variablesPrototypes.h

struct viaje {
    char identificador[MAX_TAM_IDENTIFICADOR+3];
    char ciudadDestino[MAX_TAM_CIUDAD_DESTINO+3];
    char hotel[MAX_TAM_HOTEL+3];
    int numeroNoches;
    char tipoTransporte[MAX_TAM_TIPO_TRANSPORTE+3];
    float precioAlojamiento;
    float precioDesplazamiento;
};

struct cliente {
    char dni[MAX_TAM_DNI+3];
    char nombre[MAX_TAM_NOMBRE+3];
    char apellidos[MAX_TAM_APELLIDOS+3];
    char direccion[MAX_TAM_DIRECCION+3];
    int totalViajes;
    struct viaje viajes[MAX_TAM_VIAJES_CLIENTE];
};

extern struct cliente *clientes;

文件applicationVariables.c

clientes = (struct cliente *)malloc(sizeof(struct cliente)*1);

在我的main.c中首先包括variablesPrototypes.h然后applicationVariables.c

为什么会这样?我已经测试了很多东西很长时间了,但我没有解决问题。有什么想法吗?

谢谢。

两期:

  1. struct cliente *放在applicationVariables.c中的clientes前面。您已声明 clientes,但尚未 定义它 ,因此,目前您尚未为 clientes 分配 space,您无法分配它.

  2. 像现在一样,clientes 将在全局范围内 定义 ,超出任何运行时上下文,因此您不能使用 run-time function like malloc 来初始化它。要么你只是用一个常量初始化器定义它,要么你把它移到 main() 或任何其他函数中。