gpt4 book ai didi

预处理器扩展后 clang 无法识别内联属性

转载 作者:太空宇宙 更新时间:2023-11-04 03:44:49 26 4
gpt4 key购买 nike

所以我的标题看起来像这样:

#include "compiler.h"

INLINE FUNC(boolean, DIAG_APPL_CODE) Cdd_IsXcpActive(void){
return (boolean)(Cdd_Dcm_NvM_Coding_Adaption_Block[CODING_ADAPTION_XCP_ACTIVATION_OFFSET] == 1);
}

在编译器.h中

#define INLINE inline
#define FUNC(x, y) x
typedef unsigned char boolean;

已定义

当尝试编译时我得到 -E

inline boolean Cdd_IsXcpActive(void){
return (boolean)(Cdd_Dcm_NvM_Coding_Adaption_Block[0 +1U] == 1);
}

这表明一切都在正确地进行预处理。

仍然是 clang 提示:

clang --analyze -Weverything -Wextra -std=c89 -c -g3 -O -D_lint -I . -I AID -I CDD -I COM -I config -I DIA -I MC -I MCAL -I OS -I RTE CDD/Cdd_Diag.c -o CDD/bin_ninja/Cdd_Diag.o

In file included from CDD/Cdd_Diag.c:5:
CDD/Cdd_Diag.h:32:1: error: unknown type name 'inline'
INLINE FUNC(boolean, DIAG_APPL_CODE) Cdd_IsXcpActive(void){
^
AID/Compiler.h:233:17: note: expanded from macro 'INLINE'
#define INLINE inline
^
In file included from CDD/Cdd_Diag.c:5:
CDD/Cdd_Diag.h:32:37: error: expected ';' after top level declarator
INLINE FUNC(boolean, DIAG_APPL_CODE) Cdd_IsXcpActive(void){
^
;

铿锵版本

clang version 3.4.2 (tags/RELEASE_34/dot2-final)
Target: i386-pc-cygwin
Thread model: posix

有人知道这里会发生什么吗?

最佳答案

inline 关键字是在 C99 中添加的,因此 Clang 将其视为带有 -std=c89 的类型名称。

您可以使用 -std=gnu89 标志代替 -std=c89,它支持 inline。但是请注意,它的实现语义略有不同。来自 the Clang documentation :

The *99 modes default to implementing inline as specified in C99, while the *89 modes implement the GNU version. This can be overridden for individual functions with the __gnu_inline__ attribute.

来自 the GCC documentation :

  • gnu_inline

This attribute should be used with a function that is also declared with the inline keyword. It directs GCC to treat the function as if it were defined in gnu90 mode even when compiling in C99 or gnu99 mode.
If the function is declared extern, then this definition of the function is used only for inlining. In no case is the function compiled as a standalone function, not even if you take its address explicitly. Such an address becomes an external reference, as if you had only declared the function, and had not defined it. This has almost the effect of a macro. The way to use this is to put a function definition in a header file with this attribute, and put another copy of the function, without extern, in a library file. The definition in the header file causes most calls to the function to be inlined. If any uses of the function remain, they refer to the single copy in the library. Note that the two definitions of the functions need not be precisely the same, although if they do not have the same effect your program may behave oddly.

In C, if the function is neither extern nor static, then the function is compiled as a standalone function, as well as being inlined where possible.

This is how GCC traditionally handled functions declared inline. Since ISO C99 specifies a different semantics for inline, this function attribute is provided as a transition measure and as a useful feature in its own right. This attribute is available in GCC 4.1.3 and later. It is available if either of the preprocessor macros __GNUC_GNU_INLINE__ or __GNUC_STDC_INLINE__ are defined. See An Inline Function is As Fast As a Macro.

关于预处理器扩展后 clang 无法识别内联属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25570468/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com