[C++]C++小笔记之in-line function.

当一段程序被编译成一个执行程序后,它变成了一组机器语言指令。执行时,Operating System把这组指令加载到内存中,每段指令都有一个对应的内存地址。OS会一步一步的执行指令。当执行到一个function instruction时:

  1. 程序保存当前内存地址,store function arguments to the stack, 然后jump到function的内存地址,starts to execute the function, reach to the end of the function and return to the stored memory address.
in-line function不用让程序跳到内存地址去访问function, in-line function 是在内存中直接读取。 Thus, it runs a little faster. 



To use in-line function:

1. use inline keyword to declare the function;

2. use inline keyword to define the function;


inline double Square(double x ) {return x*x;}

int main(){
double temp = Square(10);
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值