Forum: Compiler & IDEs volatile und struct


von Horst Sch. (Gast)


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;

von Nico Schümann (Gast)


Lesenswert?

Also ich hab nur die Struktur selbst als volatile gekennzeichnet, die
Elemente müsstens dann automatisch auch sein, deswegen haste n struct
genommen ;)

von mac (Gast)


Lesenswert?


von Horst Sch. (Gast)


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.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.