Endianness - How to test code for portability

Patrick Schluter Patrick.Schluter at bbox.fr
Sat Mar 13 16:59:11 UTC 2021


On Friday, 12 March 2021 at 05:53:40 UTC, Preetpal wrote:
> In the portability section of the language spec, they talk 
> about endianness 
> (https://dlang.org/spec/portability.html#endianness)  which 
> refers "to the order in which multibyte types are stored." IMO 
> if you wanted to actually be sure your code is portable across 
> both big endian and little endian systems, you should actually 
> run your code on both types of systems and test if there any 
> issues.
>
> The problem is that I am not aware of any big-endian systems 
> that you can actually test on and if there is any D lang 
> compiler support for any of these systems if they exist.
>
> This is not an important issue to me but I was just curious to 
> see if anyone actually tests for portability issues related to 
> endianness by compiling their D Lang code for a big endian 
> architecture and actually running it on that system.

Actual big endian systems? Not many around anymore:
- SPARC almost dead
- IBM z/system still around and not going away but a D 
implementation not very likely as it adds the other difficulty 
that it is not ASCII but EBCDIC.
- AVR32 doesn't look very vivid.
- Freescale Coldfire (as successor of 68K) also on a descending 
path
- OpenRISC superseded by RISC-V

Some CPU can do both but are generally used in little endian mode 
(ARM, Power) or also obsolete (Alpha, IA64).

While from an intellectual perspective endiannes support is a 
good thing, from a pure pragmatic vue it is a solved issue. 
Little endian won, definitely (except on the network in the 
TCP/IP headers).


More information about the Digitalmars-d-learn mailing list