声明一个函数为&QUOT的好处;内联"? [英] Benefits of declaring a function as "inline"?

查看:173
本文介绍了声明一个函数为&QUOT的好处;内联"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我读到C中的内联的声明中提到,这是只是一个提示编译器(即它没有遵守它)。有没有加入它,然后任何好处,或者我应该只依赖于编译器比我知道好?

Every time I read about the "inline" declaration in C it is mentioned that it is only a hint to the compiler (i.e. it does not have to obey it). Is there any benefit to adding it then, or should I just rely on the compiler knowing better than me?

推荐答案

有使用在线关键字两个原因。其一是优化的提示,你可以放心地忽略它;你的编译器是想忽略这一点。另一个原因是允许的功能在多个翻译单位存在,并且使用是绝对必要的。如果你把一个函数变成例如.H头文件,你最好把它声明内联。

There are two reasons to use the inline keyword. One is an optimization hint, and you can safely ignore it; your compiler is like to ignore it too. The other reason is to allow a function to exist in multiple translation units, and that usage is strictly necessary. If you put a function into a .h header file for example, you'd better declare it inline.

这篇关于声明一个函数为&QUOT的好处;内联"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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