Porting 32 Bit Code to 64 Bits

From D Wiki
Revision as of 23:05, 23 February 2014 by Verax (talk | contribs) (Versions)
Jump to: navigation, search

Although D is designed to make it easy to port code between 32 and 64 bit modes, being a systems programming language, dependencies can creep in. This guide points out what changes between the two.

Versions

Not all code can be made portable between 32 and 64 bits, and must be versioned. The following works:

version (X86)
    ... 32 bit code ...
else version (X86_64)
    ... 64 bit code ...
else
    static assert("unsupported target")

It is best to write versioning in that manner to give a compile time error on a new target, rather than guessing in advance what, for example, a 64 bit ARM target might require. Experience shows that guesses about how an unfamiliar platform might work always get it wrong. Save those decisions for when one is actually working on a 64 bit ARM.