Is iOS guaranteed to be little-endian?
Asked Answered
S

1

11

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.

Spikenard answered 29/10, 2019 at 19:55 Comment(4)
Don't make any assumptions. Use the proper tools to handle byte orderings so your code works regardless. Then you won't have problems when a new iOS device comes out with different byte ordering or when you add support for Mac Catalyst to your iPad app.Mayamayakovski
Fair enough, good point. Not a big deal and handling both makes the system more future-proof.Spikenard
Having developed through two three major code-impacting processor changes already in the Apple ecosystem over the last 15 years (PPC/Intel, 32/64-bit, Intel/ARM), I would definitely avoid making architecture assumptions if you can help it…Pterosaur
I've been programming ARM for DECADES, yet I have to come across anything else than little endian.Takao
C
10

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.

Curitiba answered 29/10, 2019 at 20:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.