简体   繁体   中英

Pointer to incomplete type is not allowed, defining global struct

well i'm having difficulties, i cant work with struct pointers in other .c files, always when i'm passing pointers to structs to functions not in the same .c file as the struct it annoying me with such messages. and also when i can't access struct members of one struct from other .c file i'm g what am i doing wrong? my includes? that's for example two of my structs .h files:

Server.h :

#ifndef SERVER_H
#define SERVER_H
typedef struct Server_s* Server;

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Company.h"
#include "Client.h"
#include "Order.h"
#include "SMSServer.h"
#include "MMSServer.h"

Server InstallServer(CompanyL pcompanyList , ClientL pclientList , OrderL porderList);
void RunServer(Server pmainServer);
void OrdersToDoPerTimestamp(FILE *result , Server pmainServer , int currentTimestamp);
#endif

Client.h :

#ifndef _CLIENT_H
#define _CLIENT_H
typedef struct Client_s* Client;
typedef struct ClientNODE* ClientL;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Server.h"
ClientL InstallClients(CompanyL pcompanyList , char* pfileName);
void AppendClientNode(ClientL pclientList , CompanyL pcompanyList , char* ptelNumber , char* pclientType , char* pclientCredit);
Client FindClient(ClientL pclientList, char* pclientTelNumber);
double getCostAndChargeSMSMessage(Client sourceNumber , Company sourceNumberCompany);
#endif

i can create one struck type in other .c files, but later can't access their members? please guide me a bit.

If you want to give access struct members to other files, you have to put the full struct definition into the header file. Eg:

#ifndef SERVER_H
#define SERVER_H
struct Server_s {
    int id;
};
typedef struct Server_s* Server;
#endif

The definition-less idiom you are currently using is meant to hide the implementation details from outside users: others can pass and receive pointers to the structures, but only the defining file (Server.c) can use the struct members.

如果定义可用,则只能访问结构成员,因此,如果要从多个c文件访问它们,则必须在标头中对其进行定义。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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