Tag: 易失

C99中的易失性语义

我遇到了一些我正在编写的低级代码的问题,我需要将对象用作volatile,但不一定是因为我希望将类型声明为volatile(出于可重用性的原因)。 但是,我可以定义指向结构的限定变体的指针,如以下段中所述。 struct x { int bar; }; struct x foobar; … volatile struct x *foo = &foobar; 现在foo实际上是指向该类型对象的指针: volatile struct x { volatile int x; }; 因为volatile适用于所有struct成员。 现在我的问题是当一个对象包含指向另一个对象的指针时,如何应用波动性? struct x { struct y *bar; }; 指向x的易变实例然后将其视为: volatile struct x { struct y * volatile bar; }; 或作为: volatile struct x { volatile struct y […]