c - Concatenation of two definition -
#define id proj1 #define proj id##_data.h
as per requirements definition of proj should have proj1_data.h
when print proj should give proj1_data.h ,
please me desired result. in advance !
you can print string. print proj
, need turn string.
#define stringize(x) #x #define stringize2(x) stringize(x)
stringize
applies stringizing operator on argument. turns argument string, surrounding quotation marks, , escaping contents necessary create valid string. stringize2
used allow argument expanded preprocessor before turned string. useful when want stringize expansion of macro instead of macro itself. example stringize2(__line__)
result in string represents current line in file, e.g. "1723"
. however, stringize(__line__)
results in string "__line__"
.
your definition of proj
faces similar issue. results in token id_data..h
rather proj1_data.h
. need level of expansion indirection allow id
expand before concatenate.
#define paste(x, y) x ## y #define mkfile(x) paste(x, _data.h) #define proj stingize2(mkfile(id))
using stringize2
allows mkfile
invocation expand. allowing mkfile
invoke paste
allows id
token expand.
Comments
Post a Comment