如何解决为什么IAR中的__attribute __weak无法编译?
__attribute__((weak))
main.c
#include "tmp.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int testfunc1(int a)
{
return true;
}
int main(void)
{
while (1)
{
}
}
tmp.h
#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而不是attribute((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中的
__attribute__((weak))
无法编译?为什么attribute((weak))不起作用?
因为您所使用的IAR编译器版本不支持该功能。
我相信大多数“为什么”问题都是不好的问题。对于“为什么”发生某事的答案要么太宽泛(要求解释一切),要么太模糊(因为事实就是如此)。在这种情况下,您的编译器仅不支持该特定语法。为了进一步调查“为什么” IAR Systems公司决定不为该IAR编译器版本提供对该特定语法的支持,请询问该公司。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。