www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - versions and 32 vs 64-bit code

reply Nathan Coe <robbiec1987 yahoo.com> writes:
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.
Dec 25 2011
next sibling parent "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
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.
Dec 25 2011
prev sibling next sibling parent reply =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= <xtzgzorex gmail.com> writes:
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
Dec 26 2011
next sibling parent Andrew Wiley <wiley.andrew.j gmail.com> writes:
On Mon, Dec 26, 2011 at 3:53 AM, Alex R=F8nne 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 o=


 -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, =


 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) { =A0 =A0// 64-bit ... } else { =A0 =A0// 32-bit ... } Always avoid using architecture identifiers to figure out bitness. There were plenty of cases of this in druntime and phobos which made portabilit=

 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.
Dec 26 2011
prev sibling next sibling parent Xinok <xinok live.com> writes:
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".
Dec 26 2011
prev sibling parent =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= <xtzgzorex gmail.com> writes:
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
Dec 26 2011
prev sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 12/26/11, Alex R=F8nne 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..
Dec 26 2011