gpt4 book ai didi

c++ - 位域的内存位置

转载 作者:行者123 更新时间:2023-11-30 05:43:04 25 4
gpt4 key购买 nike

摘自 2014 年 11 月的 C++14 标准工作草案:

§ 1.7 6

c ISO/IEC N4296 5 [Example: A structure declared as

struct { 
char a;
int b:5,
c:11,
:0,
d:8;
struct {int ee:8;} e;
}

contains four separate memory locations: The field a and bit-fields d and e.ee are each separate memory locations, and can be modified concurrently without interfering with each other. The bit-fields b and c together constitute the fourth memory location. The bit-fields b and c cannot be concurrently modified, but b and a, for example, can be. — end example ]

我假设 :0 充当某种分隔符,这就是为什么 d 具有单独的内存位置,而 bc 不要。但是,我不明白什么意思

together constitute the fourth memory location

bcunion 吗?例如,相当于

union {
int b:5;
int c:11;
};

最佳答案

不,它们不会像在 union 示例中那样共享任何位。

出于考虑内存位置的目的,它们仅被视为一个单元。

换句话说,以下是您示例中的部分(可能)

AAAAAAAA BBBBBCCCCCCCCCCC DDDDDDDD EEEEEEEE (ee sharing e)

空格是为了显示内存位置,不占用内存空间。

关于c++ - 位域的内存位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30337439/

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