为什么IAR中的__attribute __weak无法编译?

问题描述

我正在IAR上使用STM32F1,我使用编写了一个函数

__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编译器版本提供对该特定语法的支持,请询问该公司。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...