c - Keil ARM C 编译器 : troubles with inline functions

标签 c arm keil inline-functions

我正在移植实时内核 TNeoKernel到 Cortex-M 架构,所以我已经安装了 Keil 并正在尝试构建内核。但是,我遇到了意想不到的问题:编译器似乎无法处理 inline 函数。这是简单的代码:

static inline int test(void)
{
   return 0;
}

编译器的输出如下:

src\appl\main.c(17): warning:  #260-D: explicit type is missing ("int" assumed)
  static inline int test(void)
src\appl\main.c(17): error:  #65: expected a ";"
  static inline int test(void)

如果我删除 inline 关键字,它会编译并运行。

在 ARM 编译器的文档中,我找不到任何关于 inline 函数的信息。所以,只是为了确定:ARM 编译器真的不支持 inline 关键字吗?实在是太不可思议了,所以我决定问问。

我在内核的平台无关代码中有很多static inline函数,那么,让它支持ARM编译器的最好方法是什么?在我的脑海中,我只有两个想法:

  • 创建依赖于体系结构的宏,如 TN_INLINE,对于 ARM 编译器,它应该扩展为空;
  • 将非常小的 1 行函数转换为宏。

最佳答案

inline 关键字已在 c99 中引入,但由 default Keil ARM C编译器在c89/c90模式下编译。

基尔 documentation明确指出 inline 在 c90 中不可用:

The inline keyword is not available in C90.

Keil ARM C 编译器也支持c99。使用 --c99 编译器选项切换到 c99 模式或尝试使用 __inline在 c90 模式下的扩展关键字:

关于c - Keil ARM C 编译器 : troubles with inline functions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26899583/

相关文章:

c - 命名这个数据结构?

c++ - 宏定义中的空 # 是什么意思?

c - Keil Arm 编译器 : Is there a way to hook in the same function for two interrupts without modifying the Interrupt Vector Table?

c - 如何通过 BLE 发送 float 据并在 UART 上正确显示(nRF 工具箱)

c++ - 如何抑制第三方源文件中的警告?

c - 在 C 中将文本导出到 .txt 文件

C: printf 中的ptrdiff_t 应使用哪个字符?

c++ - libOpenCL.so 使用 VFP 寄存器参数,输出不

ios - 我如何向量化这个 for 循环?

android - 如何配置 IBM Worklight Studio 以构建 ARM 和 MIPS 设备?