i am making a program that i have decided to split in two .c files. the first program.c file has all the include files and declarations and the other unit.c file has a dozen functions and some extern declarations of global variables defined in the the main program.c
everything was working fine (compilation/linking) so far the extern variables declared in unit.c and defined in program.c are of the build in type like int or float. when i tried to use a variable of a new type from a header file that is included in program.c but not in unit.c normally the compiler complained.
to be specific the situation is like this:
program.c
#include "SDL.h"
int a;
SDL_Surface* sprite;
SDL_Surface* ghost;
unit.c
extern int a; //works fine
extern SDL_Surface* sprite; //compiler error
extern SDL_Surface* ghost; //compiler error
void funct1 (void)
{
if (sprite == ghost)
....
}
if i include SDL.h at the top of unit.c the problem is solved, but i don't want to include everything everywhere so i figured a round solution. i have declared sprite and ghost to be of type void pointer only in unit.c but the definition in program.c remains the same. like this:
unit.c
extern void* sprite;
extern void* ghost;
the compiler did not complain. i only need those extern pointers to test if they point to the same address. i did a very little bit of testing on the executable and it's working fine.
i am using the free command line Borland compiler ver 5.5.1
the question is, can this be considered legitimate in ANSI C or is it some quirk of the Borland compiler? is the only true (best practice) solution to my situation to include SDL.h in unit.c or can you please point me to some other legitimate alternative?