View Single Post
Old Apr 28th, 2005, 8:35 AM   #8
mackenga
Professional Programmer
 
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 328
Rep Power: 4 mackenga is on a distinguished road
Just a little something to add; when you're making sure your header doesn't get included twice using ifndef and define, sometimes defining a constant without a value isn't a hot idea (depends on the compiler and any other software you have parsing the program):

#ifndef _HEADER_FILE_H_
#define _HEADER_FILE_H_ 1

/* ... declarations here ... */

#endif /* _HEADER_FILE_H_ */

Obviously, don't use _HEADER_FILE_H_ as the name of your constant, but something more directly related to what you're working on and what the header file contains/is for. The _HEADER_FILE_H_ in the comment beside #endif is not strictly necessary but aids readability.

This means even if you do declare and define variables within the header file, as long as it's between the #ifndef and the #endif that matches it, that code will only be processed beyond the preprocessor once so it'll work.

If you have global variables, though, declaring them extern in the header and putting them in a file called globals.c or whatever is often a good idea. Global variables can be hard enough to keep track of after all.
mackenga is offline   Reply With Quote