简体   繁体   English

内联函数和调用约定

[英]Inline functions and calling conventions

Is there a point in specifying calling convention for an inline function? 为内联函数指定调用约定是否有意义? For example, I am writing SIMD math library, where it is recommended to use __vectorcall , but all of my functions are inline. 例如,我正在编写SIMD数学库,建议在其中使用__vectorcall ,但是我所有的函数都是内联的。 In some articles I have seen people inlining all function and still saying, that you need to compile the library with default __vectorcall convention (or actually putting this attribute). 在某些文章中,我看到人们内联所有功能,但仍然说,您需要使用默认的__vectorcall约定编译该库(或实际上放置此属性)。
I can see the difference in assembly, when function is not inline. 当函数不是内联时,我可以看到汇编的区别。 But what is the point to specify calling convention for inline function since it is not really a function call? 但是,由于内联函数实际上不是函数调用,因此为内联函数指定调用约定有什么意义呢? Isn't it better to specify __vectorcall only for not inline function? 只为非内联函数指定__vectorcall更好吗?

The inline keyword is only a suggestion to the compiler; inline关键字只是对编译器的建议; it doesn't guarantee that the function will be inlined. 它不能保证函数会被内联。 For example, a recursive function can't be inlined, and if you use function pointers the compiler may need to generate non-inline copies of otherwise inlined functions. 例如,不能内联递归函数,如果使用函数指针,则编译器可能需要生成否则为内联函数的非内联副本。 Additionally, constraints on memory and space might stop the compiler from inlining a function. 此外,对内存和空间的限制可能会阻止编译器内联函数。

As a result, even if you mark a function inline, you'll still to specify a calling convention if appropriate because there's no guarantee that the compiler will indeed eliminate the function call. 结果,即使您将函数标记为内联,您仍将在适当的情况下指定调用约定,因为无法保证编译器确实会消除函数调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM