Programming

Thursday, October 11, 2007

Reversing the #include idiom

There's an idiom in C and C++ whereby of you include a header file, you write
#ifndef FILE_H_INCLUDED
#define FILE_H_INCLUDED

// stuff

#endif
It occurs to me that it should actually be
#ifndef EXCLUDE_FILE1_H
#define EXCLUDE_FILE1_H

#endif
This is a minor point, however it means that you can legitimately exclude certain header files if for some reason you don't want to include them:
gcc foo.c -DEXCLUDE_FILE1_H