Not sure how to word this but, Is there any way to increment a macro?
I have several offset macros, the first defined offset must be zero, the next one must be 1, and so on. If I need to add an offset macro to the middle of the list, it can be cumbersome to increment all the offsets below it manually.
//How can I turn this... // v This number needs to increment by 1 (no matter the order) #define OFFSET_X 0 #define OFFSET_Y 1 #define OFFSET_Z 2 #define OFFSET_W 3 //Into something like this... (order of macros swapped yet the numbering still goes from 0 to 3) int num = 0; #define OFFSET_Z num++ // = 0 (was 2) #define OFFSET_Y num++ // = 1 (was 1) #define OFFSET_X num++ // = 2 (was 0) #define OFFSET_W num++ // = 3 (was 3)
enuminstead?__COUNTER__is not standard afaik.