versions and 32 vs 64-bit code

Alex Rønne Petersen xtzgzorex at gmail.com
Mon Dec 26 01:53:44 PST 2011


On 26-12-2011 06:41, Nathan Coe wrote:
> Is there a way to change what is compiled in based on whether the -m32 or -m64
> option is chosen? I can see that there are predefined versions (for X86 and
> X86_64 e.g.), but I don't know if this is based on the compile options, or the
> platform the compilation is being performed on. As an example, if I am
> compiling on a 64-bit intel machine, is the version X86 or X86_64 set by default?
> Thanks.

Use:

version (D_LP64)
{
     // 64-bit ...
}
else
{
     // 32-bit ...
}

Always avoid using architecture identifiers to figure out bitness. There 
were plenty of cases of this in druntime and phobos which made 
portability very annoying (they are fixed now, though).

- Alex


More information about the Digitalmars-d mailing list