c - 为什么 IAR 中的 __attribute__((weak)) 无法编译?
问题描述
我正在 IAR 上研究 STM32F1,我编写了一个弱函数使用
__attribute__((weak))
主程序
#include "tmp.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int testfunc1(int a)
{
return true;
}
int main(void)
{
while (1)
{
}
}
时间
#include <stdio.h>
#include <stdlib.h>
int testfunc1(int a);
tmp.c
#include "tmp.h"
__attribute__((weak)) int testfunc1(int a)
{
}
它编译时出现错误:
Error[Pe079]: expected a type specifier
Warning[Pe606]: this pragma must immediately precede a declaration
Error[Pe260]: explicit type is missing ("int" assumed)
Error[Pe141]: unnamed prototyped parameters not allowed when body is present
Error[Pe130]: expected a "{"
Error while running C/C++ Compiler
但是,如果我使用 __weak 而不是属性((弱)),它会按预期正常工作。
tmp.c
#include "tmp.h"
__weak int testfunc1(int a)
{
}
.
Warning[Pe940]: missing return statement at end of non-void function "testfunc1"
Done. 0 error(s), 1 warning(s)
那么,为什么属性((弱))不起作用?
解决方案
为什么
__attribute__((weak))
在 IAR 中无法编译?为什么属性((弱))不起作用?
因为您使用的 IAR 编译器版本不支持它。
我相信大多数“为什么”问题都是不好的问题。对“为什么”某事发生的答案要么太宽泛(需要解释一切),要么太模糊(因为事情就是这样)。在这种情况下,您的编译器只是不支持该特定语法。为了进一步调查“为什么”,IAR Systems 公司决定不为该 IAR 编译器版本实现对特定语法的支持,请询问该公司。
推荐阅读
- terraform - 无法创建嵌套动态块
- mysql - 如何通过更改列值创建与表中当前行对应的新行
- python - Python 不更新 SQL Server 表
- php - 在 cPanel 中一段时间后重新加载/刷新 php 文件
- generics - Object Pascal 中的泛型:类型相等
- angular - 基于登录用户类型的导航 - Angular
- powershell - 如何使用powershell重命名文件?
- walmart-electrode - 发生错误:命令失败:./gradlew lib:uploadArchives
- flutter - 小部件库捕获的异常,方法 '>=' 在 null 上调用
- mysql - mysql突然崩溃了。升级_57