Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I wonder if there is something like #elseifdef directive (or similar)?
I know there is #elif but what if the "else" is about a directive being defined (#ifdef)?
Posted
Comments
[no name] 18-Aug-15 8:41am    
#if defined(CREDIT)
credit();
#elif defined(DEBIT)
debit();
#else
printerror();
#endif


See https://msdn.microsoft.com/de-de/library/ew2hz0yd(v=vs.120).aspx[^]
Michael Haephrati 18-Aug-15 8:46am    
Great solution!
[no name] 18-Aug-15 8:52am    
Thank you :)
CPallini 18-Aug-15 8:51am    
Better than mine. Have my virtual 5.
[no name] 18-Aug-15 8:52am    
Thank you :)

1 solution

No, there is not.

However,
C++
#ifdef FOO
  // foo stuff
#elseifdef BOO
  // boo stuff
#endif


would be equivalent to

C++
#ifdef FOO
  // foo stuff
#else
  #ifdef BOO
    // boo stuff
  #endif
#endif



[update]
I post (strictly without authorization :-) )
the (much better) alternative proposed by 0x01AA
C++
#if defined(CREDIT)
credit();
#elif defined(DEBIT)
debit();
#else
printerror();
#endif

[/update]
 
Share this answer
 
v2
Comments
[no name] 18-Aug-15 8:54am    
My 5 for both ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900