Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is iOS guaranteed to be little-endian?

It appears that ARM processors can be configured as big-endian or little-endian. However, according to the interwebs, ARM processors are "almost always" configured as little-endian. Is it guaranteed that iOS will run an ARM processor in little-endian mode? Is there a compile-time flag which I could check, via #if or anything else?

Although there are functions in Foundation to handle different byte orderings, it seems that one could save some trouble about that if one could be sure that the byte ordering was always the same.

like image 471
Robert Dodier Avatar asked Oct 29 '19 19:10

Robert Dodier


People also ask

Is Little Endian default?

Little-endian is the default memory format for ARM processors. In little-endian format, the byte with the lowest address in a word is the least-significant byte of the word. The byte with the highest address in a word is the most significant.

Are Macs Little Endian?

All replies. Little-endian. "On the Macintosh platform, PowerPC-based Macintosh computers use big endian addressing, while Intel-based Macs use little-endian addressing."

What systems use little endian?

The following platforms are considered little endian: VAX/VMS, AXP/VMS, Digital UNIX, Intel ABI, OS/2, and Windows. On big endian platforms, the value 1 is stored in binary and is represented here in hexadecimal notation. One byte is stored as 01, two bytes as 00 01, and four bytes as 00 00 00 01.

How do you know if a system is little endian?

Since size of character is 1 byte when the character pointer is de-referenced it will contain only first byte of integer. If machine is little endian then *c will be 1 (because last byte is stored first) and if the machine is big endian then *c will be 0.


1 Answers

At the time of this writing, iOS runs the ARMs in little-endian mode. However, for architectures supporting multiple endiannes, it's considered good practice to handle both cases without making any assumptions of how the higher layer software/firmware runs it. The reasons are future code changes that affect endiannes or architectural changes resulting in a fixed endiannes mode. Apple has changed CPU architecture multiple times, that alone should be a hint, and the fact that today's microprocessor and microcontroller market is being actively driven forward with new products and developments means that more than a good practice, it's almost a must. Software and hardware vendors, in the mobile/smart appliances sector are known to change their CPU architecture with regularity. Plus, and more importantly, proper handling of multiple byte ordering will lead you to a robust, solid and future-proof solution.

like image 66
Javier Silva Ortíz Avatar answered Oct 19 '22 07:10

Javier Silva Ortíz