Here is a sample of my macros:
#define STR(val) #val #define STRX(val) STR(val) #define LINE_ STRX(__LINE__) #define SRC_STR __FILE__":"LINE_ #define SRC_STRN SRC_STR"\n" #define PRINT_IF(cond) ((cond)&&(printf("\""#cond"\" is true: "SRC_STRN)>=0)) #define PRINT_IFNOT(cond) ((!(cond))&&(printf("\""#cond"\" is false: "SRC_STRN)>=0)) #define PRINT_IFN PRINT_IFNOT #define PRINT_IFEQ(a,b) PRINT_IF(a==b) #define PRINT_FMT(val,fmt) printf(#val" = "#fmt": "SRC_STRN,val) #define PRINT_INT(i) PRINT_FMT(i,%d) #define PRINT_LONG(i) PRINT_FMT(i,%ld) #define PRINT_UINT(i) PRINT_FMT(i,%u) #define PRINT_ULONG(i) PRINT_FMT(i,%lu) #define PRINT_HEX(i) PRINT_FMT(i,%x) #define PRINT_FLT(flt) PRINT_FMT(flt,%g) #define PRINT_PTR(ptr) PRINT_FMT(ptr,%p) #define PRINT_STR(str) PRINT_FMT(str,%s) I want to define another list of macros related to this one, but I'd like to avoid having to type everything. I've already written one example:
#ifndef UNITTEST #define PRINT_INT_U(x) ((void)sizeof(x)) #else #define PRINT_INT_U(x) PRINT_INT(x) #endif You can see that I want my PRINT_..._U functions to evaluate to nothing when I am not running unit tests, so that I can spam it and not worry about them popping up all over the place during debug or production.
So my question is, is there some crazy method using the preprocessor to generate new #define statements? My guess is that there is not...
edit: Could I at least do something like this? make a list:
INT LONG UINT ULONG HEX FLT PTR STR and then insert them all each into the pattern
#define PRINT_%LI%_U(x) PRINT_%LI%(x) where %LI% represents an item from the list.