[英]Inline function cross compilation issues for ARMv8 architecture using aarch64 linux android clang
I have a questions about using inline keyword in C code (C99). 我对在C代码(C99)中使用内联关键字有疑问。 I know C99 inline semantics are different than C++ or gnuC inline rules, I have read 我知道C99内联语义不同于C ++或gnuC内联规则,我已阅读
http://www.greenend.org.uk/rjk/tech/inline.html http://www.greenend.org.uk/rjk/tech/inline.html
and 和
but, I just can't get this working. 但是,我只是无法正常工作。
I have a function definition as below in file1.c 我在file1.c中具有如下函数定义
inline myfunc(arguments)
{
}
And this function is called from another function in file2.c 并且此函数是从file2.c中的另一个函数调用的
In that file2.c I tried using 在那个file2.c中,我尝试使用
extern inline myfunc(arguments);
for this function before it is called from the other function 在从其他函数调用之前,此函数
still I keep getting error - implicit declaration of myfunc 我仍然不断收到错误-myfunc的隐式声明
or undefined reference error if I remove the extern inline 或删除未定义的内联错误
Due to my code structure, cannot have the myfunc function definition in a header file nor can have it as static inline, as it has to be called from different compilation units. 由于我的代码结构,无法在头文件中包含myfunc函数定义,也不能将其作为静态内联,因为必须从不同的编译单元调用它。
What is that I am getting wrong? 我弄错了什么? How to fix it. 如何解决。
After lot of reading about this, trial and error I have found answer to my problem above in a way I was looking for - Inline a C function definition present in a C source file, using C99 rules, without putting it in a header file. 经过大量阅读,反复试验后,我发现了上述问题的答案,这是我一直在寻找的答案-使用C99规则内联存在C源文件中的C函数定义,而无需将其放在头文件中。 I added the attribute always_inline keyword to the function definition and declaration as below and recompiled, it inlines the call to that function. 我将属性always_inline关键字添加到函数定义和声明中,如下所示,然后重新编译,它内联了对该函数的调用。 In file file1.c 在文件file1.c中
__attribute__((always_inline)) void myfunc(arguments)
{
//... function definition
}
and in file1.h which has its declaration , I changed it to be as below 在具有声明的file1.h中,我将其更改为如下
__attribute__((always_inline)) void myfunc(arguments);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.