Careful Where You Put Your Hash
22:37 Saturday, 26 March 2005
In which we discover the delights of # placement.
If you’ve written code for more than one platform you’ve probably come across something that looks like this:
#if defined(_WIN32)
#elif defined(LINUX)
#endif
A lot of us indent to make things more readable so you might end up with this:
#if defined(_WIN32)
#include <io.h>
#elif defined(LINUX)
#include <ioctl.h>
#endif
According to K&R that’s valid. But some tools don’t do what you think. Take makedepend for example. I just discovered that if the line does not start with # then makedepend ignores it. So that file you think makedepend was picking up as an include is silently ignored. If you’re relying on makedepend you really should write the statements like this:
#if defined(_WIN32)
# include <io.h>
#elif defined(LINUX)
# include <ioctl.h>
#endif
I know compilers (e.g. gcc) can output dependency statements but I’ve found makedepend to be much faster. So I guess, until I fix makedepend, I’ll be paying more attention to where I put my hash from now on.