volatile und struct

Gast #365059
Lesenswert?

Hallo, eine kurze Frage an die Experten:

Ich habe eine Interrupt Routine die ein struct verändert:

typedef struct
{
  volatile uint8_t trid;   // Tx, RX id
  volatile uint8_t arq_cnt;    // command or response
  volatile uint8_t length; // packet length
  volatile uint16_t crc;   // 16-bi crc checksum
  uint8_t volatile *data;  // pointer to the main data
} modem_frame;

Frage:
Reicht es, wenn ich die die struct variable selber als volatile
deklariere, oder muss ich - wie oben gemacht - alle Elemente des
struct's zusätzlich als volatile declarieren?

Oder muss ich die einzelnen Elemente des struct's als volatile
deklarieren und die Deklaration der Variable modem_frame braucht nicht
mehr als volatile deklariert werden?

Oder beides zusammen, also so:

modem_frame volatile *rx_frame;
Gast #365062
Lesenswert?

Danke, Lösung ist also:

Finally, if you apply volatile to a struct or union, the entire
contents of the struct/union are volatile. If you don't want this
behavior, you can apply the volatile qualifier to the individual
members of the struct/union.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren