versions and 32 vs 64-bit code

Andrew Wiley wiley.andrew.j at gmail.com
Mon Dec 26 02:07:58 PST 2011


On Mon, Dec 26, 2011 at 3:53 AM, Alex Rønne Petersen
<xtzgzorex at gmail.com> wrote:
> 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).
>

+1
This makes things like, say, running code on ARM much much simpler. If
you don't actually need X86, don't require it.


More information about the Digitalmars-d mailing list