What’s the difference between these two declarations, and is one preferred over the other?
typedef struct IOPORT {
GPIO_TypeDef* port;
u16 pin;
} IOPORT;
typedef struct {
GPIO_TypeDef* port;
u16 pin;
} IOPORT;
As far as which style is preferred, I prefer the 1st style (with the name in both the struct tag and as a typedef for the struct) simply because there are no drawbacks other than a few more characters in the source file. My IDE’s struct snippet drops the name in both places, so I always get a typedef’ed struct name along with a struct tag name.
You get a few small benefits:
struct STRUCTNAME” can be used to declare pointers to the struct within the structBut, if I happen to manually type in the struct definition, I’ll often lazily neglect declaring one or the other name.