There has been a few cases where I've seen preprocessor code like the following:
#ifndef TOKEN
#define TOKEN
#endif
To me, it seems that in this situation (I'm aware of it's use when wrapped around items other than it's self (including include guards for those who are still answering)), it is redundant to check if TOKEN is already defined before defining it. If I were to just #define it, without the checks, the result is the same.
Is there a common reason for this? Compilation times? Reserving the block for future additions?
Thanks.
Because you may get macro redefinition warnings otherwise. For example, we have some third party dll's who have headers with things like the following.
#define PI 3.14
As these are defined in third party headers, we have no control over them and cannot remove or rename them. If we also try to define Pi ourselves, we would get a macro redefinition warning. So you have two options,
1) Use their macro, and guard against redefinition
#ifndef PI
#define PI 3.14
#endif
2) Remove their definition, then define your own
#ifdef PI
#undef PI
#endif
#define PI 3.14