【问题标题】:Peculiar struct type特殊的结构类型
【发布时间】:2021-02-03 21:49:50
【问题描述】:

所以我在查看 Microchip 的 dsPIC MCU 头文件时偶然发现了这个结构:

/* 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;

我似乎无法弄清楚这里的类型或实例是什么(以及这样做的目的是什么):

  1. 什么是tagUART?
  2. 什么是UART?
  3. 什么是*PUART?

【问题讨论】:

  • /questions/252780/why-should-we-typedef-a-struct-so-often-in-c -- 首先搜索“[c] typedef struct”。

标签: c struct microchip


【解决方案1】:

这是一种一体机的形式

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

【讨论】:

    【解决方案2】:

    什么是tagUART?

    这是结构的名称。

    什么是UART?

    这是结构的类型定义/别名。

    什么是*PUART?

    这是指向结构的指针的类型定义/别名。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-14
      • 1970-01-01
      • 2011-10-24
      • 1970-01-01
      • 1970-01-01
      • 2011-11-23
      • 1970-01-01
      相关资源
      最近更新 更多