This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Single line conditional compiles
- From: "Gerrit van Niekerk" <gerritvn at gpvno dot co dot za>
- To: random at bubblescope dot net
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 28 Jul 2005 21:48:55 +0200
- Subject: Re: Single line conditional compiles
- References: <42E91D4D.22097.1B3092F9@localhost>
- Reply-to: gerritvn at gpvno dot co dot za
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