gpt4 book ai didi

c - 对于编译器,C struct 如何忽略内部顺序?

转载 作者:太空狗 更新时间:2023-10-29 15:26:39 25 4
gpt4 key购买 nike

例如,我们有两个结构:

struct type1 {
int t;
char c;
};

struct type2 {
char c;
int t;
};

C 编译器在哪个阶段可以忽略顺序差异并将它们确定为相同的结构?以及如何?

最佳答案

In which stage can a C compiler ignore the difference in order and settle them as a same struct? And how?

编译器不会忽略结构成员声明的顺序。事实上,结构保证成员在内存中的布局与它们声明的顺序相同,尽管在结构对齐需要时插入了填充位。因此,编译器总是会将 struct type1struct type2 视为不同的类型。

关于c - 对于编译器,C struct 如何忽略内部顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23182617/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com