如何编写尾数无关的C / C ++ code? [英] How to write endian agnostic C/C++ code?

查看:146
本文介绍了如何编写尾数无关的C / C ++ code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一些谷歌搜索,但没有找到关于这个问题的好文章。我应该注意实施,我想成为尾数无关的应用程序时?

I did some googling and couldn't find any good article on this question. What should I watch out for when implementing an app that I want to be endian-agnostic?

推荐答案

这可能是一个很好的文章供您阅读:的字节顺序谬论

This might be a good article for you to read: The byte order fallacy

计算机的字节顺序没有多大意义可言除了编译器作者之类的,谁大惊小怪映射到注册个字节的内存分配。机会是你不是一个编译器作者,所以计算机的字节顺序不应该的问题给你一个位。

The byte order of the computer doesn't matter much at all except to compiler writers and the like, who fuss over allocation of bytes of memory mapped to register pieces. Chances are you're not a compiler writer, so the computer's byte order shouldn't matter to you one bit.

注意短语计算机的字节顺序。什么事确实是一个外围设备或连接codeD数据流的字节顺序,但 - 这是关键的一点 - 计算机做处理的字节顺序是无关的数据本身的处理。如果数据流EN codeS值与字节顺序B,则算法脱code计算机字节顺序C对的值应该是关于B,不是B和C之间的关系。

Notice the phrase "computer's byte order". What does matter is the byte order of a peripheral or encoded data stream, but--and this is the key point--the byte order of the computer doing the processing is irrelevant to the processing of the data itself. If the data stream encodes values with byte order B, then the algorithm to decode the value on computer with byte order C should be about B, not about the relationship between B and C.

这篇关于如何编写尾数无关的C / C ++ code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆