简体   繁体   English

如何声明易失性结构的C数组

[英]how to declare C array of volatile struct

I defined a struct and I do not want to put the volatile into the struct because other instance may not need it (eg RAM caching). 我定义了一个结构,我不想将volatile放入该结构中,因为其他实例可能不需要它(例如RAM缓存)。 Now I need that a particular array of this struct be volatile. 现在,我需要此结构的特定数组易失。

typedef struct{
    uint8_t rxPacket[FIFO_SIZE];
    uint8_t length;
    int8_t rssi;
    uint8_t lqi;
}rawRx_t;

Is this the right way to have each (struct) element of the array volatile ? 这是使数组的每个(结构)元素易失的正确方法吗?

static volatile rawRx_t rawRxBuffer[NB_MAX_RX_FRAME];

Yes. 是。

Paring it down and switching the type to something cdecl.org can parse, we get: 将其缩减并将其类型切换为cdecl.org可以解析的内容,我们得到:

volatile int rawRxBuffer[];

and the corresponding output is: 相应的输出是:

declare rawRxBuffer as array of volatile int

the point is that it's an "array of volatile", ie each array element is volatile. 关键是它是一个“易失性数组”,即每个数组元素都是易失性的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM