C++: 结构体是否可以根据字节序的不同而具有不同的大小?

huangapple go评论66阅读模式
英文:

C++: Is there a case when a struct can have different sizes depending on the endianness?

问题

我在一本教材上看到,当字节序更改时,结构体的大小可能会发生变化。我不确定,但我认为示例是

struct X { int a, char b };

请有人解释一下这是否正确?

英文:

So I read on a textbook that there are specific cases when the struct can change sizes when the endianness is changed. I am not sure, but I think that the example was

struct X { int a, char b };

Can someone explain if this is true ?

答案1

得分: 1

A change in endianness means you are on a different system where the compiler is free to define padding, integer size and byte size which could all lead to a different struct size, but it would not be because of the endianness.

英文:

A change in endianness means you are on a different system where the compiler is free to define padding, integer size and byte size which could all lead to a different struct size, but it would not be because of the endianness.

huangapple
  • 本文由 发表于 2023年2月27日 16:13:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75578087.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定