Reputation: 17576
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.
Upvotes: 11
Views: 8468
Reputation: 2982
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.
Upvotes: 10