简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM