wrt: C preprocessor macro specialisation based on an argument
I am trying to use this technique to compare to 'void', however it also matches 'void *'.
Has anybody else seen this problem ? Is there a known solution ?
The source contains thousands of lines with preprocessor macros, so it is not easily readable. However it is like this:
#define GIVE_A_FUNCTION(RetType,Name,ArgType1)\
RetType Name(ArgType1 ArgName1) \
{ \
SWITCH_ON_VOID( \
RetType,\
,\
RetType value =)\
GetValue(); \
PostProcessing(); \
SWITCH_ON_VOID( \
RetType,\
,\
return value;)\
}
This expands to nothing if type is 'void *', hence I do not include the return statement.
I can solve the problem manually but would prefer not to.
Regards,
voidis only used as a function return meaning "no return" andvoid *refers to a pointer. Hencevoidis not a type, butvoid *is._Generic?typein an incorrect context butvoidsec is not a type. E.g.: "A parameterlist of type void is equivalent to the empty parameter list" could also be said as "A parameterlist specified asvoidmeans the empty parameterlist" (Note that in C the truely empty paramaterlist,()means the function can take any number of parameters.)#define prm /*empty*/\n typedef void myRetVal; myRetVal func(myRetval prm) {gSideEffect++; }sounds funny (confusing). It can be used here to enable when the type in the future changes and has some advantages over a#define. To define "no type" the keywordvoidis apparently necessary to be treated by the compiler as a type, but void, meaning "nothing", is only a syntactic construct with no real world effect (returning "nothing": ax register has no meaning, passing "nothing": parameter stack has no meaning).