he leído la siguiente pregunta y la respuesta parece bastante claro: How to concatenate twice with the C preprocessor and expand a macro as in "arg ## _ ## MACRO"?¿Cómo concatenar cadenas con el preprocesador C con puntos en ellas?
Pero lo que si la variable tiene un punto al final?
Estoy tratando de hacer una macro simple que incremente los contadores en una estructura para depuración. Puedo hacer esto fácilmente, incluso sin la ayuda de la pregunta anterior, simplemente con
#ifdef DEBUG
#define DEBUG_INC_COUNTER(x) x++
#endif
y llamarlo
DEBUG_INC_COUNT(debugObj.var1);
embargo, la adición "debugObj." para cada macro parece terriblemente redundante. Sin embargo si intento para concatenar:
#define VARIABLE debugObj.
#define PASTER(x,y) x ## y++
#define EVALUATOR(x,y) PASTER(x,y)
#define DEBUG_INC_COUNTER(x) EVALUATOR(VARIABLE, x)
DEBUG_INC_COUNTER(var)
gcc -E macro.c
me sale
macro.c:6:1: error: pasting "." and "var" does not give a valid preprocessing token
Entonces, ¿cómo debo cambiar esto para que
DEBUG_INC_COUNTER(var);
genera
debugObj.var++;
?
D'oh! Me volví demasiado inteligente allí. – Makis