Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
December 26, 2011 versions and 32 vs 64-bit code | ||||
---|---|---|---|---|
| ||||
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. |
December 26, 2011 Re: versions and 32 vs 64-bit code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nathan Coe | On Monday, 26 December 2011 at 05:41:11 UTC, Nathan Coe wrote: > As an example, if I am compiling on a 64-bit intel machine, is the version X86 or X86_64 set by default? The predefined version identifiers specify the *target* architecture. Note that the default target architecture matches the architecture of the compiler binary: the 64-bit DMD compiler has -m64 by default (use -m32 to override). http://dlang.org/version.html#PredefinedVersions lists predefined version identifiers. |
December 26, 2011 Re: versions and 32 vs 64-bit code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nathan Coe | 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
|
December 26, 2011 Re: versions and 32 vs 64-bit code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex Rønne Petersen | On Mon, Dec 26, 2011 at 3:53 AM, Alex Rønne Petersen <xtzgzorex@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.
|
December 26, 2011 Re: versions and 32 vs 64-bit code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex Rønne Petersen | On 12/26/11, Alex Rønne Petersen <xtzgzorex@gmail.com> wrote:
> Use:
>
> version (D_LP64)
> {
> // 64-bit ...
> }
> else
> {
> // 32-bit ...
> }
So why doesn't D_LP32 exist? If you already use "version(X86) else
version(X86_64)" you're going to have to swap all of your code around
if you start using D_LP64..
|
December 26, 2011 Re: versions and 32 vs 64-bit code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On 12/26/2011 8:23 AM, Andrej Mitrovic wrote:
> On 12/26/11, Alex Rønne Petersen<xtzgzorex@gmail.com> wrote:
>> Use:
>>
>> version (D_LP64)
>> {
>> // 64-bit ...
>> }
>> else
>> {
>> // 32-bit ...
>> }
>
> So why doesn't D_LP32 exist? If you already use "version(X86) else
> version(X86_64)" you're going to have to swap all of your code around
> if you start using D_LP64..
I agree, but I don't think D_LP32 would be correct since LP stands for "long pointer".
|
December 26, 2011 Re: versions and 32 vs 64-bit code | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On 26-12-2011 14:23, Andrej Mitrovic wrote:
> On 12/26/11, Alex Rønne Petersen<xtzgzorex@gmail.com> wrote:
>> Use:
>>
>> version (D_LP64)
>> {
>> // 64-bit ...
>> }
>> else
>> {
>> // 32-bit ...
>> }
>
> So why doesn't D_LP32 exist? If you already use "version(X86) else
> version(X86_64)" you're going to have to swap all of your code around
> if you start using D_LP64..
I don't think it's a big deal. You should write your code for D_LP64 in the first place anyway.
- Alex
|
Copyright © 1999-2021 by the D Language Foundation