Using two flags in conditonal compilation (version)

Justin Whear via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 25 13:30:28 PDT 2014


On Wed, 25 Jun 2014 20:24:30 +0000, Danyal Zia wrote:

> Hi, In the development of my library, I'm in a position where I need to
> add support for multiple compilers. For instance, supporting both the
> assembly of LDC/DMD and GDC. I want to do something like:
> 
> version(DigitalMars && LDC)
> {
> }
> 
> However, it doesn't compile which forces me to rewrote the same code for
> both DigitalMars and LDC
> 
> version(DigitalMars)
> {
> }
> 
> version(LDC)
> {
> }
> 
> Is there a way to check both versions at the same time? (I can't seem to
> find the solution through google, sorry)
> 
> Thanks,
> Danyal Zia

I think you mean ||, not &&.  The best way I know around this is to 
define enums:

version (DigitalMars)
   enum compiler_DigitalMars = true;
else
   enum compiler_DigitalMars = false;

//... similar for LDC

static if (compiler_DigitalMars || compiler_LDC)
{
   ...
} else {
   ...
}


More information about the Digitalmars-d-learn mailing list