Should variable definition be in header files?

One thing that I’ve used in the past (when global variables were in vogue): var.h file: … #ifdef DEFINE_GLOBALS #define EXTERN #else #define EXTERN extern #endif EXTERN int global1; EXTERN int global2; … Then in one .c file (usually the one containing main()): #define DEFINE_GLOBALS #include “var.h” The rest of the source files just include … Read more

Self-sufficient header files in C/C++

A self sufficient header file is one that doesn’t depend on the context of where it is included to work correctly. If you make sure you #include or define/declare everything before you use it, you have yourself a self sufficient header. An example of a non self sufficient header might be something like this: —– … Read more