Search code examples
cdatabasestructerror-handlingtypedef

dereferencing pointer to incomplete type - typedef struct


I am looking for an error in my code (in C) and I am not finding anything. I've looked on many blogs and tried many things that were advised but nothing helped.
I've coded that :

typedef struct Account_t *Account;
struct Account_t {
     Customer customer;
     Realtor realtor;
     Offer offer;
};

while Realtor, Customer and Offer are well defined and included with a .h file. I am getting an error that says "dereferencing pointer to incomplete type 'struct Account_t' " when I write:

 Account account = malloc(sizeof(*account));

Please help me find the problem !


Solution

  • Compile problem, should be handled with correct type conversion and correct type allocation. Taking in consideration that Account is declares as pointer to Account_t, see the typedef, the correct sizeof should be taken from Account_t or Account* or *account. But pointer conversion to Account.
    I'd say, you have to do something like this:

    Account account = (Account)malloc(sizeof(*account));