What\'s the difference between these two declarations, and is one preferred over the other?
typedef struct IOPORT {
GPIO_TypeDef* port;
u16
For the sake of readability it's preferred to express the original example in a form such as:
typedef struct IOPORT_t {
GPIO_TypeDef* port;
u16 pin;
} IOPORT;
....which emphasizes the difference between type and instance.
Furthermore, if you want to add initialisers you can do something like:
typedef struct IOPORT_t {
GPIO_TypeDef* port;
u16 pin;
} IOPORT;
struct IOPORT_t IOPORT2 = {
.port = NULL,
.pin = 25
};
or you can lose the typedef to initialise it directly:
struct IOPORT_t {
GPIO_TypeDef* port;
u16 pin;
} IOPORT = {
.port = NULL,
.pin = 24
};
struct IOPORT_t IOPORT2 = {
.port = NULL,
.pin = 25
};