Hi All
I'm trying to setup a struct in a file called mytest.c, which will be included/used in my main file
I have the following test program:
mytest.c
Code:
#include <stdio.h>
#include <stdlib.h>
struct CONFIG {
int *x ;
} *_c ;
void init_extern(void)
{
_c = malloc(sizeof(*_c)) ;
int f = 11 ; // or _c->x = malloc( sizeof(*_c->x) ) ;
_c->x = &f ; // *_c->x = 13 ;
printf("value is %d (%p)\n", *_c->x, &_c );
}
mytest.h
Code:
#ifndef ADD_H
#define ADD_H
void init_extern(void);
extern struct CONFIG *_c ;
#endif /* ADD_H */
and the main program is:
Code:
#include <stdio.h>
#include "mytest.h"
int main(void)
{
init_extern();
printf("value is %d (%p)\n", *_c->x, &_c );
return 0;
}
When I try to compile I get
Code:
$ gcc mymain.c mytest.c
mymain.c: In function ‘main’:
mymain.c:7: error: dereferencing pointer to incomplete type
The problem is with the printf in main. However in mytest.c it works just fine (if I comment out that line). Any suggestions ?
thnx
LuCa