Ites to Bytes:Endianess是一个值得关注的问题?

Dan*_*ark 0 objective-c endianness

在这种情况下我是否必须担心字节顺序(整数必须是0-127):

    int a = 120;
    int b = 100;
    int c = 50;
    char theBytes[] = {a, b, c};
Run Code Online (Sandbox Code Playgroud)

I think that, since each integer sits in its own byte, I don't have to worry about Endianess in passing the byte array between systems. This has also worked out empirically. Am I missing something?

Chu*_*uck 6

字节顺序仅影响单个值中字节的顺序.单个字节不受端序问题的影响,并且数组总是顺序的,因此字节数组在大端和小端架构上是相同的.

请注意,这并不一定意味着仅使用chars将使数据类型100%字节可移植.例如,结构可能仍然包含依赖于体系结构的填充,并且一个系统可能具有未签名的chars而另一个系统使用了签名(尽管我看到您通过仅允许0-127来回避这一点).