Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different types - different endianness?

Tags:

c

endianness

I'm working on rather old code atm, and this code tests the endianness of types like short, int, long and long long separately.

Are there systems "still in use" that actually have different endianness for different types (due to different sizes of these types)? The only example that I know of is the PDP-11, where the two 16 bit halves of 32 bit values are stored in "big endian order" whereas the two 8 bit halves of each of these 16 bit are stored in "little endian order".

Due to undefined behavior in the mentioned tests I probably need to rewrite parts of this and want to know if it's worth the effort to keep that complexity. I know that (and how) I can write code that's independent of the system endianness, but this would be a lot of changes that I currently don't have the time for.

like image 214
Daniel Jour Avatar asked Aug 07 '16 19:08

Daniel Jour


1 Answers

Big endian machines are still in use, in digital signal processors (DSP) where TI provides numerous examples, and in general purpose processors where the Motorola 68000 is an example. Notably, in some DSP and RISC processors (c.f. ARM and Power), endianess is configurable and sometimes at multiple levels.

Here is an example by TI that combines big-endian and little-endian processors for particular functionality, "OMAP910 Device"

The history of endianess in general purpose processors is described in the following IEEE article, Endianess in personal computers

Reasons for using a DSP or ARM in a design include that the device may be optimized for a particular functionality, more cost effective, require less supporting circuity, or use less power compared to a general purpose processor. The OMAP910 demonstrates endianess for an intended functionality.

Code developed to run on platforms with different endianess, is often conditionalized for the endianess of the platform and where configurable and relevant, the rule is generally to explicitly set or detect the endianess.

like image 118
DrM Avatar answered Sep 18 '22 05:09

DrM