Re: Preprocessing directive in the middle of macro arguments
- From: Ark Khasin <akhasin@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 17 Jan 2008 09:36:29 GMT
John Bode wrote:
On Jan 16, 8:57 am, Francois Grieu <fgr...@xxxxxxxxx> wrote:The OP's code has no embedded directives; it's equivalent toOne of the C compiler that I use <OT>(Keil's CX51)</OT> barks at
#define a(b) b
int main(void){return a(
#if 0
#endif
0);}
More generally, this compiler seems confused by any preprocessing
directive in the middle of macro arguments, which comes handy e.g. to
conditionaly select one of several arguments passed to a macro.
Is it a compiler bug? Where does C89 define if this is valid or not?
TIA.
Francois Grieu
It's not a bug; you cannot embed preprocessor commands in a macro.
All preprocessor directives are processed before any macro expansion
takes place, so any preprocessor directives embedded in a macro will
not be recognized as such, but will instead be translated as regular C
code.
#define a(b) b
int main(void){return a(
0);}
Which is good C, IMHO. So I think it's a compiler bug.
<OT>
Getting the C front end right is surprisingly hard; there are enough C vendors to make a market for C front end parsers, and it exists.
Still, some people do it on their own, and sometimes incorrectly. I had trouble with Keil for ARM (see http://www.macroexpressions.com/dl/compileme.c), but I never tried their latest version.
I wonder if this fixes the OP problem :)
#de\
fine \
a(b\
b)=bb
</OT>
--
Ark
.
- Follow-Ups:
- Re: Preprocessing directive in the middle of macro arguments
- From: Ben Bacarisse
- Re: Preprocessing directive in the middle of macro arguments
- References:
- Preprocessing directive in the middle of macro arguments
- From: Francois Grieu
- Re: Preprocessing directive in the middle of macro arguments
- From: John Bode
- Preprocessing directive in the middle of macro arguments
- Prev by Date: Re: NULL pointers
- Next by Date: Re: NULL pointers
- Previous by thread: Re: Preprocessing directive in the middle of macro arguments
- Next by thread: Re: Preprocessing directive in the middle of macro arguments
- Index(es):
Relevant Pages
|