K
kenkahn
Given the following simple c program
#include <stdio.h>
enum ATTRTYPE {
CFG_ATTR = 3000
};
int main() {
#define xx(id) printf("ATTR=%s\n",#id);
xx(CFG_BADATTR);
return 0;
}
Compiling this on AIX, Solaris or Linux using gcc (or xlC or CC)
results in the following output:
ATTR=CFG_ATTR
Looking at the preprocessor shows the macro expanding to
printf("ATTR=%s\n","CFG_BADATTR");
Is this use of '#' in a macro to access the literal string of an
enumeration value documented? I can't find it in the gcc manual (or
any other C compiler manual). But it does seem to work on all
platforms for multiple C compilers. Can I assume it will continue to
work or is this a fluke?
(I inherited this code and just recently figured out what this macro
was doing)
#include <stdio.h>
enum ATTRTYPE {
CFG_ATTR = 3000
};
int main() {
#define xx(id) printf("ATTR=%s\n",#id);
xx(CFG_BADATTR);
return 0;
}
Compiling this on AIX, Solaris or Linux using gcc (or xlC or CC)
results in the following output:
ATTR=CFG_ATTR
Looking at the preprocessor shows the macro expanding to
printf("ATTR=%s\n","CFG_BADATTR");
Is this use of '#' in a macro to access the literal string of an
enumeration value documented? I can't find it in the gcc manual (or
any other C compiler manual). But it does seem to work on all
platforms for multiple C compilers. Can I assume it will continue to
work or is this a fluke?
(I inherited this code and just recently figured out what this macro
was doing)