The forgotten #error C macro

in #programming7 years ago (edited)

I have have honestly never seen this macro used until a few days ago, but I find it pretty useful. The #error C macro helps you set up conditions it your program that must be met before your program compiles, otherwise it will throw an error specifying the file, line number and error message that were thrown. This is useful because in some situations you don't want your program to compile with default options and want the user to set those before they continue.

An example of a way you would use it would be something like this:

#ifdef OPT_A
    // Option A chosen
#elif OPT_B
    // Option B chosen
#else
    #error Please choose an option
#endif

You could use it for any option that MUST be defined for your program to compile correctly, or any constants your program might need.

Coin Marketplace

STEEM 0.21
TRX 0.25
JST 0.038
BTC 98320.57
ETH 3439.18
USDT 1.00
SBD 3.12