P99
Macros
Preprocessor conditionals

This provides different types of if-else clause for the preprocessor. More...

+ Collaboration diagram for Preprocessor conditionals:

Macros

#define P99_IF_ELSE(...)   P99_IF_EQ_0(P99_IS_EQ_0(__VA_ARGS__))
 A preprocessor control structure. More...
 
#define P99_IF_EMPTY(...)   P99_IF_EQ_1(P99_IS_EMPTY(__VA_ARGS__))
 
#define P99_IF_EQ(A, B)   P00_IF_CLAUSE(P99_PASTE4(P00_IS_,A,_EQ_,B)())
 Test if two words A and B are equal. More...
 
#define P99_IF_EQ_0(N)   P99_IF_EQ(0, N)
 Test if token N is the token 0. More...
 
#define P99_IF_EQ_1(N)   P99_IF_EQ(1, N)
 Test if token N is the token 1. More...
 
#define P99_IF_EQ_2(N)   P99_IF_EQ(2, N)
 Test if token N is the token 2. More...
 
#define P99_IF_EQ_3(N)   P99_IF_EQ(3, N)
 Test if token N is the token 3. More...
 
#define P99_IF_EQ_4(N)   P99_IF_EQ(4, N)
 Test if token N is the token 4. More...
 
#define P99_IF_GE(A, B)   P99_IF_EQ_1(P99_IS_GE(A, B))
 Test two decimal numbers A and B for whether A is greater than or equal to B. More...
 
#define P99_IF_GE_0(A)   P00_IF_CLAUSE(P99_PASTE4(P00_IS_,A,_GE_,0)())
 
#define P99_IF_GT(A, B)   P99_IF_EQ_1(P99_IS_GT(A, B))
 Test two decimal numbers A and B for whether A is strictly greater than B. More...
 
#define P99_IF_LE(A, B)   P99_IF_EQ_1(P99_IS_LE(A, B))
 Test two decimal numbers A and B for whether A is less than or equal to B. More...
 
#define P99_IF_LT(A, B)   P99_IF_EQ_1(P99_IS_LT(A, B))
 Test two decimal numbers A and B for whether A is strictly less than B. More...
 
#define P99_IF_LT_0(A)   P00_IF_NOT_CLAUSE(P99_PASTE4(P00_IS_,A,_GE_,0)())
 
#define P99_IF_NE(A, B)   P00_IF_NOT_CLAUSE(P99_PASTE4(P00_IS_,A,_EQ_,B)())
 Test if two words A and B are unequal. More...
 
#define P99_IF_void(...)   P99_IF_EQ_1(P99_IS_EQ_void(__VA_ARGS__))
 
#define P99_IF_VOID(...)   P99_IF_EQ_1(P99_IS_VOID(__VA_ARGS__))
 
#define P99_PRAGMA(...)   P99_IF_EMPTY(__VA_ARGS__)()(P00_PRAGMA(__VA_ARGS__))
 An wrapper of the _Pragma keyword. More...
 

Detailed Description

This provides different types of if-else clause for the preprocessor.

The macros in this group are analogous to P99_IF_EQ

P99_IF_EQ(INT_MAX, 10000)(short)(long) a;
P99_IF_EQ(8, CHAR_BIT)(uint8_t)(uint_least8_t) c;

which would normally 5 be textually replaced by

long a;
uint8_t c;

That is, all these macros expect three pairs of parentheses after their keyword token:

  1. containing the condition
  2. containing the if-clause
  3. containing the else-clause

For the underlying logical and arithmetical operations

See also
Preprocessor Boolean operations
Preprocessor arithmetic operations
Footnotes:
5 INT_MAX can never be 10000, because is it at least 215-1. CHAR_BIT isn't 8 only on special hardware such as DSP, and if is is 8, the typedef uint8_t must exist.