位域的内存位置
Memory location of bit-fields
来自 C++14 标准的 2014 年 11 月工作草案:
§ 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
有一个单独的内存位置,而 b
和 c
没有。但是,我不明白
是什么意思
together constitute the fourth memory location
b
和c
是union
吗?例如,相当于
union {
int b:5;
int c:11;
};
不,它们不会像 union
示例中那样共享任何位。
出于考虑内存位置的目的,它们仅被视为一个单元。
换句话说,以下是您示例中的位(可能)
AAAAAAAA BBBBBCCCCCCCCCCC DDDDDDDD EEEEEEEE (ee sharing e)
space是为了显示内存位置,不占用任何space内存。
来自 C++14 标准的 2014 年 11 月工作草案:
§ 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
有一个单独的内存位置,而 b
和 c
没有。但是,我不明白
together constitute the fourth memory location
b
和c
是union
吗?例如,相当于
union {
int b:5;
int c:11;
};
不,它们不会像 union
示例中那样共享任何位。
出于考虑内存位置的目的,它们仅被视为一个单元。
换句话说,以下是您示例中的位(可能)
AAAAAAAA BBBBBCCCCCCCCCCC DDDDDDDD EEEEEEEE (ee sharing e)
space是为了显示内存位置,不占用任何space内存。