16

我正在使用嵌入式设备,并且有一些代码最初是使用 IAR 编译器编译的。

我正在尝试使用 GCC 编译器重新编译所述代码。

有一个特定的语句: typedef __IO,它根本没有被编译(“无法识别的符号错误”)。

谁能建议我如何让这个语句正确编译?

4

3 回答 3

14

如果无法识别,那将是因为未包含包含定义的适当系统标题。

它将在工具链提供的芯片支持头文件中定义。它是类型限定符#define,或者更确切地说是一个将扩展为类型限定符的宏 ( )。例如,它的用法如下:

__IO uint8_t CSSR;

uint8_t是类型,所以 __IO 实际上不能是 a typedef,因为它不用于类型有效的地方。__IO 宏扩展为特定编译器所需的任何内容,以确保正确的 I/O 访问和寻址。在 I/O 是内存映射的典型情况下,它将简单地扩展为,volatile因为所有 I/O 都应声明为 volatile 以确保不会优化显式访问。

如果您想确定,请下载 IAR 工具的演示版本并查看头文件,了解它是如何为您的特定架构定义的。否则你可能只是使用#define __IO volatile

于 2013-01-16T22:42:38.147 回答
8

_IO 表示 C 语言中的 volatile ......它不会优化代码,并且使用 _IO 为变量声明的值将是不可预测的,或者会在不了解编译器和用户的情况下发生变化

于 2014-05-06T09:13:29.637 回答
5

这是一个老问题,但如果有人想知道 ARM 微控制器的这个问题,您可以在 CMSIS 库中看到该定义。例如,__IO对于 cortex-m4 的定义如下:

#define     __IO    volatile             /*!< Defines 'read / write' permissions */

完整块复制粘贴在下面(Source):

#ifdef __cplusplus
  #define   __I     volatile             /*!< Defines 'read only' permissions */
#else
  #define   __I     volatile const       /*!< Defines 'read only' permissions */
#endif
#define     __O     volatile             /*!< Defines 'write only' permissions */
#define     __IO    volatile             /*!< Defines 'read / write' permissions */

/* following defines should be used for structure members */
#define     __IM     volatile const      /*! Defines 'read only' structure member permissions */
#define     __OM     volatile            /*! Defines 'write only' structure member permissions */
#define     __IOM    volatile            /*! Defines 'read / write' structure member permissions */
于 2018-01-06T15:43:39.817 回答