Hi
This is probably a common mistake but I still don't understand why I get an error.
I have an .h file where I declare a struct (and functions):
Code:
struct _HNum;
typedef struct _HNum HNum;
In a .c file I define the struct as following and lets say allocate some memory to it:
Code:
struct _HNum {
int sign; // 0 is + , 1 is -
int noofdigits; // no of elements in digits
int nofndigits; // no of nonzero elements in digits
char *digits;
};
HNum *HNum_alloc() {
HNum *H = (HNum*)malloc(sizeof(HNum));
//if( H != NULL )
//{
H->sign=0;
H->noofdigits=0;
H->nofndigits=0;
H->digits = (char*)calloc(10,sizeof(char));
//}
return H;
}
In my main file I then want to check if it works and did:
Code:
HNum *n1 = HNum_alloc();
printf("%i",n1->sign);
HNum_free(n1);
When I compile I get the error:
error: dereferencing pointer to incomplete type
at the printf line.
I don't understand why n1->sign does not access the right thing.
Thanks for any tips!