struct是class-key的其中一个: class-key: class, struct, union
在c++ 11 标准文档里有一个经典的结构体解析:
如此这般,比特域和临近的非比特域是在各自独立的内存位置。所以可以对这两个域做同时访问而互不影响。
[ Note: Thus a bit-field and an adjacent non-bit-field are in separate memory locations, and therefore can be
concurrently updated by two threads of execution without interference. The same applies to two bit-fields,
if one is declared inside a nested struct declaration and the other is not, or if the two are separated by
a zero-length bit-field declaration, or if they are separated by a non-bit-field declaration. It is not safe to
concurrently update two bit-fields in the same struct if all fields between them are also bit-fields of non-zero
width. —end note ]
还可以看到特殊的用法是 零长度的比特域。
5 [ Example: A structure declared as
struct {
char a;
int b:5,
c:11,
:0,
d:8;
struct {int ee:8;} e;
}
上面这个结构体包含,四个独立的内存位置:a,b&c,d,e.ee。b和c共同组成了第四个内存位置。b和c不能同时访问。
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 ]
|