C Programming. Global.h file

Status
Not open for further replies.

James Carter

Beta member
Messages
2
I am a little rusty with C programming and how to structure multiple file format for successful compilation. I created at .h
file which holds my global variables (global.h). However, using IAR compiler, I get a complaint about one of my vaiables saying
that I am attempting to redefine said variable. I checked to
see if the typing was consistent and it is. I even commented out the variable call in the one file, but the compiler still complains.

I recall that the use of extern is used to deal with these issues of global variables, but I cannot remember how to structure the files. And I don't know whether the use of extern type would even resolve this issue.
 
So... you're trying to include a header file?
Have you tried
Code:
#include "filename"
I believe this is for files specific to a program

Or

Code:
#include <filename>
Here I believe this is for universal (built in) files.

-SkyHi
 
I remember what you have to do. In the global.h file, you declare your external variable, such as "extern unsigned char ColorSelect." Then you produce a global.c file which contains your noraml storage variables, such as "unsigned char ColorSelect."

Your global.h is included as a header file, and the global.c file gets compiled with the other project .c files.

Thanks
 
Status
Not open for further replies.
Back
Top Bottom