
[英]Is this the right way to implement a return statement in a function? My function won't return a value
[英]Is there some way to tell the compiler that certain function's return value won't change?
我使用库 libA,而后者又使用库 libB。 现在,libB 有一个“当前 macguffin”的线程本地索引。 其他线程(除非它们开始写入内存中的任意位置)无法更改当前线程的“当前 macguffin”。 现在,libA 不知道你在调用它的函数之间没有改变当前的 macguffin,所以当你编译一个 libA function 时,你会得到类似的东西:
callq 123 <libB::get_current_macguffin()+0x12>
# other stuff here
在 object 文件中。 如果您进行了许多libA
调用并且不更改当前的 macguffin - 您最终会进行许多libB::get_current_macguffin()
调用,而您不应该这样做。
现在,有没有办法告诉编译器(或 linker 做 LTO):
libB::set_current_macguffin(macguffin_t new_macguffin)
)...以某种方式使其放弃后续调用并缓存结果?
笔记:
libA
和libB
已经编译,我无法重新编译它们。 但是 - libA 的一些代码可能是 header 中的内联函数; 或者编译器本身可能会复制 libA 代码以避免调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.