Define and undef

Just like you can define additional symbols and their values for the preprocessor when running Xpanda from the command like so:

Xpanda.exe file.fsh CONSTANT=1

you can also define them in the expanded files themselves using the #define directive. The only difference is that the symbol names must start with X_ (uppercase letter x and underscore):

#define X_CONSTANT 1

This can be very useful for example when creating many permutations of the same file:

// Uber.vsh:
#ifdef X_A
    // Do something when X_A is defined...
#endif

#ifdef X_B
    // Do something when X_B is defined...
#endif

// File 1:
#define X_A
#pragma include("Uber.vsh")

// File 2:
#define X_B
#pragma include("Uber.vsh")

Which would expand to:

// File 1:
#define X_A
#pragma include("Uber.vsh")
    // Do something when X_A is defined...
// include("Uber.vsh")

// File 2:
#define X_B
#pragma include("Uber.vsh")
    // Do something when X_B is defined...
// include("Uber.vsh")

You can also undefine these symbols later using the #undef macro:

#define X_A

#ifdef X_A
    // This WILL be included, because X_A is defined.
#endif

#undef X_A

#ifdef X_A
    // This WILL NOT be included, because X_A is not defined anymore at this
    // point!
#endif
Do you find this page helpful?

Copyright © 2022, Patrik Kraif. Built on April 23, 2022 using GMDoc.