* Single line conditional compiles
@ 2005-07-28 16:02 Gerrit van Niekerk
2005-07-28 16:08 ` random
2005-07-28 16:16 ` Eljay Love-Jensen
0 siblings, 2 replies; 4+ messages in thread
From: Gerrit van Niekerk @ 2005-07-28 16:02 UTC (permalink / raw)
To: gcc-help
How can one implement single line conditional compile macros with GCC?
Instead of having:
#ifdef OPT1
<valid C line>
#endif
Having something like:
IFOPT1 <valid C line>
The following works with BorlandC, but not GCC:
#ifdef OPT1
#define IFOPT1
#else
#define IFOPT1 /##/
#endif
I understand why it does not work - I am looking for a solution, not an
explanation :)
===============================================
Gerrit van Niekerk
GP van Niekerk Ondernemings BK
Roosstraat 211, Meyerspark, 0184, South Africa
Tel: +27(12)8036501 Fax SA: 0866 413 555
Fax Int'l: +12(06)2034131
Email: gerritvn@gpvno.co.za
Web: http://www.gpvno.co.za
===============================================
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Single line conditional compiles
2005-07-28 16:02 Single line conditional compiles Gerrit van Niekerk
@ 2005-07-28 16:08 ` random
2005-07-28 19:51 ` Gerrit van Niekerk
2005-07-28 16:16 ` Eljay Love-Jensen
1 sibling, 1 reply; 4+ messages in thread
From: random @ 2005-07-28 16:08 UTC (permalink / raw)
To: gerritvn; +Cc: gcc-help
Gerrit van Niekerk wrote:
>How can one implement single line conditional compile macros with GCC?
>
>Instead of having:
>
>#ifdef OPT1
><valid C line>
>#endif
>
>Having something like:
>IFOPT1 <valid C line>
>
>The following works with BorlandC, but not GCC:
>
>#ifdef OPT1
>#define IFOPT1
>#else
>#define IFOPT1 /##/
>#endif
>
>I understand why it does not work - I am looking for a solution, not an
>explanation :)
>
>
>
Not quite what you are looking for, but how about?
#ifdef OPT1
#define IFOPT1(x) x
#else
#define IFOPT1(x)
#endif
Then you write
IFOPT1(stuff)
This has the advantage you can write it mid-line, with stuff before and
after it.
Chris
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Single line conditional compiles
2005-07-28 16:02 Single line conditional compiles Gerrit van Niekerk
2005-07-28 16:08 ` random
@ 2005-07-28 16:16 ` Eljay Love-Jensen
1 sibling, 0 replies; 4+ messages in thread
From: Eljay Love-Jensen @ 2005-07-28 16:16 UTC (permalink / raw)
To: gerritvn, gcc-help
Hi Gerrit,
> I understand why it does not work - I am looking for a solution, not an
explanation :)
Well, that's good, because you saved me time explaining. :-)
One solution is to run the preprocessor twice.
The first time it does all the normal preprocessor things (pulling in the
#include, expanding macros, yada yada yada), including embedding those
now-invalid comments into the post-preprocessed output.
The second time removes those introduced comments.
Voila!
--Eljay
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Single line conditional compiles
2005-07-28 16:08 ` random
@ 2005-07-28 19:51 ` Gerrit van Niekerk
0 siblings, 0 replies; 4+ messages in thread
From: Gerrit van Niekerk @ 2005-07-28 19:51 UTC (permalink / raw)
To: random; +Cc: gcc-help
On 28 Jul 2005 at 17:07, random@bubblescope.net wrote:
> Gerrit van Niekerk wrote:
>
> >How can one implement single line conditional compile macros with GCC?
> >
> >Instead of having:
> >
> >#ifdef OPT1
> ><valid C line>
> >#endif
> >
> >Having something like:
> >IFOPT1 <valid C line>
> >
> >The following works with BorlandC, but not GCC:
> >
> >#ifdef OPT1
> >#define IFOPT1
> >#else
> >#define IFOPT1 /##/
> >#endif
> >
> >I understand why it does not work - I am looking for a solution, not an
> >explanation :)
> >
> >
> >
> Not quite what you are looking for, but how about?
>
> #ifdef OPT1
> #define IFOPT1(x) x
> #else
> #define IFOPT1(x)
> #endif
>
> Then you write
> IFOPT1(stuff)
>
> This has the advantage you can write it mid-line, with stuff before and
> after it.
>
> Chris
Thanks Chris,
This is a workable solution and portable too!
Gerrit
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-07-28 19:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-28 16:02 Single line conditional compiles Gerrit van Niekerk
2005-07-28 16:08 ` random
2005-07-28 19:51 ` Gerrit van Niekerk
2005-07-28 16:16 ` Eljay Love-Jensen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).