Łukasz Przeniosło
Łukasz Przeniosło

Reputation: 2949

Peculiar struct type

So I was reviewing the Microchip's dsPIC MCU header file and stumbled upon this construct:

/* Generic structure of entire SFR area for each UART module */
typedef struct tagUART {
        uint16_t uxmode;
        uint16_t uxsta;
        uint16_t uxtxreg;
        uint16_t uxrxreg;
        uint16_t uxbrg;
} UART, *PUART;

I cannot seem to figure out what is a type or instance here (and for what end was this designed like that):

  1. What is tagUART?
  2. What is UART?
  3. What is *PUART?

Upvotes: 1

Views: 38

Answers (2)

kaylum
kaylum

Reputation: 14044

What is tagUART?

It's the name of the struct.

What is UART?

It's a typedef/alias for the struct.

What is *PUART?

It's a typedef/alias for a pointer to the struct.

Upvotes: 2

prog-fh
prog-fh

Reputation: 16910

It's a kind of all-in-one form of

struct tagUART { // the structure itself with all its details
        uint16_t uxmode;
        uint16_t uxsta;
        uint16_t uxtxreg;
        uint16_t uxrxreg;
        uint16_t uxbrg;
};

typedef struct tagUART UART; // UART is a shorter name for struct tagUART
typedef struct tagUART *PUART; // PUART is a pointer-type to such a struct

Upvotes: 5

Related Questions