tags:

views:

93

answers:

2

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 the 1 and 0 stand for? thanks in advance

+5  A: 

The #if 1 triggers the first group of #defines, 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.)

Marcelo Cantos
thanks!so whats the need to have both of them if we always know that we will execute the first ZXP?
rabidmachine9
@rabidmachine: You can switch to use the other set by changing the first line to `#if 0`
UncleBens
+1  A: 

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.

DeadMG