C ++内联函数使用GCC - 为什么CALL? [英] C++ inline functions using GCC - why the CALL?

查看:209
本文介绍了C ++内联函数使用GCC - 为什么CALL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在测试C ++中的内联函数调用。

I have been testing inline function calls in C++.

Thread model: win32
gcc version 4.3.3 (4.3.3-tdm-1 mingw32)

在C ++编程语言中的Stroustrup wirtes:

Stroustrup in The C++ Programming language wirtes:


内联说明符是一个提示,指示编译器应该尝试生成代码[...] inline而不是放置函数的代码一次,然后通过通常的函数调用机制调用。

The inline specifier is a hint to the compiler that it should attempt to generate code [...] inline rather than laying down the code for the function once and then calling through the usual function call mechanism.

但是,我发现生成的代码不是内联的。对于 isquare 函数有一个 CALL 字符。

However, I have found out that the generated code is simply not inline. There is a CALL instrction for the isquare function.

为什么会发生?

Why is this happening? How can I use inline functions then?

编辑:使用的命令行选项:

**** Build of configuration Debug for project InlineCpp ****

**** Internal Builder is used for build               ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\InlineCpp.o ..\src\InlineCpp.cpp
g++ -oInlineCpp.exe src\InlineCpp.o


推荐答案

没有通用的C ++方法FORCE编译器创建内联函数。注意你引用的文本中的'提示'一词 - 编译器没有义务听你的。

There is no generic C++ way to FORCE the compiler to create inline functions. Note the word 'hint' in the text you quoted - the compiler is not obliged to listen to you.

如果你真的,绝对要做一些内联,您将需要一个特定于编译器的关键字,或者您需要使用宏而不是函数。

If you really, absolutely have to make something be in-line, you'll need a compiler specific keyword, OR you'll need to use macros instead of functions.

编辑:njsf在他的回应中提供了正确的gcc关键字。

njsf gives the proper gcc keyword in his response.

这篇关于C ++内联函数使用GCC - 为什么CALL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆