Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
743 views
in Technique[技术] by (71.8m points)

struct - C Typedef - Incomplete Type

So, out of the blue, the compiler decides to spit this in face: "field customer has incomplete type".

Here's the relevant snippets of code:

customer.c

#include <stdlib.h>
#include <string.h>

#include "customer.h"

struct CustomerStruct;
typedef struct CustomerStruct
{
    char id[8];
    char name[30];
    char surname[30];
    char address[100];
} Customer ;

/* Functions that deal with this struct here */

customer.h

A header file for customer.h

#include <stdlib.h>
#include <string.h>

#ifndef CUSTOMER_H
#define CUSTOMER_H

    typedef struct CustomerStruct Customer;

    /* Function prototypes here */

#endif

This is where my problem is:

customer_list.c

#include <stdlib.h>
#include <string.h>

#include "customer.h"
#include "customer_list.h"

#include "..utilsutils.h"


struct CustomerNodeStruct;
typedef struct CustomerNodeStruct
{
    Customer customer; /* Error Here*/
    struct CustomerNodeStruct *next;
}CustomerNode;



struct CustomerListStruct;
typedef struct CustomerListStruct
{
    CustomerNode *first;
    CustomerNode *last;
}CustomerList;

/* Functions that deal with the CustomerList struct here */

This source file has a header file, customer_list.h ,but I don't think its relevant.

My Problem

In customer_list.c, at the line with the comment /* Error Here */, the compiler complains about field customer has incomplete type.

I've been googling this problem all day, and now im at the point of pulling out my eyeballs and blending them with strawberries.

What is the source of this error ?

Thanks in advance :)

[P.S. if I forgot to mention something, let me know. Its been a stressful day for me, as you might tell ]

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Move the struct declaration to the header:

customer.h
typedef struct CustomerStruct
{
...
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...