ImageCraft Products FAQ-O-Matic : All Compilers — V6 — may also apply to V7 : How do I handle global variables in a multi-file project?
It is fairly simple – general rule is one file DEFINES the variable, and any number of files can reference the variables by DECLARING it. For example, in file1, you can write int foo; // this defines foo in file2, etc. you write extern int foo; // this declares foo A typical “trick” is to put something like this in a header file that all files: #include foo.h #ifdef MAIN #define EXTERN #else #define EXTERN extern #endif EXTERN int foo; and in file1.c, you write #define MAIN #include “foo.h” // this will define foo In file2.c and other files, you simply write #include “foo.h” // this will declare foo kristil@imagecraft.
Related Questions
- ImageCraft Products FAQ-O-Matic : All Compilers -- V6 -- may also apply to V7 : How come the mouse scroll wheel doesn work in the editor?
- ImageCraft Products FAQ-O-Matic : All Compilers -- V6 -- may also apply to V7 : How do I handle global variables in a multi-file project?
- ImageCraft Products FAQ-O-Matic : All Compilers -- V6 -- may also apply to V7 : What microcontrollers do you support?