extra-macroarg

Manage arguments of macros in C.

Manage arguments of macros in C.

Download: header file.

get

// Get nth argument.
EMA_GET<N>(args)
// get index 0 (first) argument
printf("EMA_GET0(a0, a1, a2): %s.\n", EMA_GET0("a0", "a1", "a2"));

// get max of 3 values using variable argument (variadic) macro
#define MAX2(A, B) ((a)>(b)? (a) : (b))
#define MAX3(A, B, C) MAX2(MAX2(A, B), C)
#define MAX(...) EMA_GET0(EMA_GET3(__VA_ARGS__, MAX3, MAX2)(__VA_ARGS__))
printf("MAX(7, 1, 2): %d.\n", MAX(7, 1, 2));

count

// Count number of arguments.
EMA_COUNT(args)
printf("EMA_COUNT(3, 5, 2, 3): %d.\n", EMA_COUNT(3, 5, 2, 3));

geteven

// Get even index arguments.
EMA_GETEVEN(args)
printf("EMA_GETEVEN(7, 1, 2, 3): %d, %d.\n", EMA_GETEVEN(7, 1, 2, 3));

getodd

// Get odd index arguments.
EMA_GETODD(args)
printf("EMA_GETODD(7, 1, 2, 3): %d, %d.\n", EMA_GETODD(7, 1, 2, 3));

prefix

// Prefix all arguments with a value.
EMA_PREFIX(value, args)
printf("EMA_PREFIX(7, 1, 2, 3): %d, %d, %d.\n", EMA_PREFIX(7, 1, 2, 3));

postfix

// Postfix all arguments with a value.
EMA_POSTFIX(value, args)
printf("EMA_POSTFIX(7, 1, 2, 3): %d, %d, %d.\n", EMA_POSTFIX(7, 1, 2, 3));

merge

// Merge all arguments.
EMA_MERGE(args)
printf("EMA_MERGE(7, 1, 2, 3): %d.\n", EMA_MERGE(7, 1, 2, 3));

mergepair

// Merge all arguments pairs.
EMA_MERGEPAIR(args)
printf("EMA_MERGEPAIR(7, 1, 2, 3): %d, %d.\n", EMA_MERGEPAIR(7, 1, 2, 3));

join

// Join all arguments, with separator.
EMA_JOIN(separator, args)
printf("EMA_JOIN(7, 1, 2, 3): %d.\n", EMA_JOIN(7, 1, 2, 3));

joinpair

// Join all argument pairs, with separator.
EMA_JOINPAIR(separator, args)
printf("EMA_JOINPAIR(7, 1, 2, 3): %d, %d.\n", EMA_JOINPAIR(7, 1, 2, 3));

space

// Space arguments, a character apart.
EMA_SPACE(args)
printf("EMA_SPACE(h, b, c, d): %s.\n", EMA_SPACE("h", "b", "c", "d"));

spacepair

// Space argument pairs, a character apart.
EMA_SPACEPAIR(args)
printf("EMA_SPACEPAIR(h, b, c, d): %s, %s.\n", EMA_SPACEPAIR("h", "b", "c", "d"));



cppf