Reputation: 7985
Can somebody explain the following code please?
#if 1
// loop type
#define FOR_IS_FASTER 1
#define WHILE_IS_FASTER 0
// indexing type
#define PREINCREMENT_IS_FASTER 1
#define POSTINCREMENT_IS_FASTER 0
#else
// loop type
#define FOR_IS_FASTER 1
#define WHILE_IS_FASTER 0
// indexing type
#define PREINCREMENT_IS_FASTER 0
#define POSTINCREMENT_IS_FASTER 1
#endif
#if PREINCREMENT_IS_FASTER
#define ZXP(z) (*++(z))
#define ZX(z) (*(z))
#define PZ(z) (++(z))
#define ZP(z) (z)
#define ZOFF (1)
#elif POSTINCREMENT_IS_FASTER
#define ZXP(z) (*(z)++)
#define ZX(z) (*(z))
#define PZ(z) (z)
#define ZP(z) ((z)++)
#define ZOFF (0)
#endif
I can understand what the functions are doing but for example how does the pre-processor choose which ZXP will be execute if we call it later? What do the 1 and 0 stand for?
Upvotes: 0
Views: 165
Reputation: 147028
I'm probably inclined to agree with UncleBens and suggest that it's done so that you don't understand it, because the whole lot is totally useless.
Upvotes: 1
Reputation: 186078
The #if 1
triggers the first group of #define
s, which set PREINCREMENT_IS_FASTER to 1. Because of this, #if PREINCREMENT_IS_FASTER
triggers the first #define ZXP...
.
There is nothing exceptional about 1 and 0 in this context. The #if
preprocessor directive succeeds if its argument is non-zero.
You can switch to the alternate form by changing the #if 1
at the top of the file with #if 0
. (Thank you @rabidmachine for the tip.)
Upvotes: 6