calling a macro with ommitted input parameter?

S

Spiro Trikaliotis

Hello,

assume I define a macro like

#if <somecondition>
# define MACRO(_x, _y) _x
#else
# define MACRO(_x, _y) _y
#endif


Now, I call it later with

MACRO(/* no parameter */, ABC)

or

MACRO(ABC, /* no parameter */)


Is this legal in C90 and/or C99? This is, can I ommit parameters to
MACRO by just leaving the contents out?


Some background on why I'm asking this:

I'm using this construction (I'm lazy ;-)) with gcc and the Microsoft
Compiler, and until now, it worked perfectly.

Anyway, just recently, I found out that if I run the Microsoft
Compiler with a special switch ("prefast"), it behaves somehow
"unrationally". To me, it seems that although <somecondition> is true,
it uses the "wrong" macro.

Now, my question is: Is the above legal C? That is, should I expect it
to work, or is the Microsoft Compiler right in behaving unexpectedly, as
my code is outside of the language C?

Many thanks,
Spiro.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,159
Messages
2,570,881
Members
47,418
Latest member
NoellaXku

Latest Threads

Top