C++ what happens to a value that is returned but is not stored?(C ++返回但未存储的值会发生什么?)
问题描述
假设我有一个返回 int 的函数.我不存储函数调用的值.我认为它没有存储在内存中并消失在以太中,但我不知道.谢谢.
Say I have a function that returns an int. I don't store the value from the function call. I presume that it is not stored in memory and fades into the aether, but I don't know.
Thank you.
推荐答案
int 返回值通常存储在寄存器中(例如,32 位或 64 位 Intel 上的 EAX 或 RAX,分别).
An int return value will normally be stored in a register (e.g., EAX or RAX on 32-bit or 64-bit Intel, respectively).
它不会褪色.当编译器出于其他目的需要该寄存器时,它只会被覆盖.如果有问题的函数是内联扩展的,编译器可能会检测到该值没有被使用,并省略编写或计算该值的代码.
It won't fade. It'll simply be overwritten when the compiler needs that register for some other purpose. If the function in question is expanded inline, the compiler may detect that the value isn't used, and elide the code to write or compute the value at all.
这篇关于C ++返回但未存储的值会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C ++返回但未存储的值会发生什么?
基础教程推荐
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- CString 到 char* 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
