1

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,

17
  • 1
    Can you post an example? To my knowledge void is only used as a function return meaning "no return" and void * refers to a pointer. Hence void is not a type, but void * is. Commented Jun 22, 2015 at 14:10
  • Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer! Also see how to ask Commented Jun 22, 2015 at 14:10
  • Can you rely on C11's _Generic? Commented Jun 22, 2015 at 14:35
  • 1
    @Mints97, it is "linguistig haggling" as the standard uses the word type in an incorrect context but void sec 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 as void means the empty parameterlist" (Note that in C the truely empty paramaterlist, () means the function can take any number of parameters.) Commented Jun 25, 2015 at 8:29
  • 1
    Mints97, let's continue the haggling: #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 keyword void is 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). Commented Jun 25, 2015 at 9:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.