83. Structures-ii

Question.1

Two developers access a peripheral register at address 0x40010000:

Style A — Struct overlay:

typedef struct {
   volatile uint32_t CTRL;
   volatile uint32_t STATUS;
   volatile uint32_t DATA;
} Periph;
#define PERIPH ((Periph*)0x40010000)
PERIPH->CTRL = 0x01;

Style B — Direct pointer:

#define CTRL  (*(volatile uint32_t*)0x40010000)
#define STATUS (*(volatile uint32_t*)0x40010004)
CTRL = 0x01;

Which is better for a peripheral with 10+ registers?

Need Help? Refer to the Quick Guide below

Select Answer

Restart quiz!