C ++发生了什么,返回的值,但没有存储? [英] C++ what happens to a value that is returned but is not stored?

查看:111
本文介绍了C ++发生了什么,返回的值,但没有存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个返回 int 的函数。我不存储函数调用的值。我认为它不会被存储在内存中,并会淡入到以太网中,但我不知道。
谢谢。

解决方案

int 通常存储在寄存器中(例如,分别在32位或64位Intel上的EAX或RAX)。

它不会褪色。当编译器需要为其他目的进行注册时,它将被简单地覆盖。如果所讨论的函数是以内联方式扩展的,那么编译器可能会检测到该值未被使用,并使代码根本无法写入或计算该值。

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.

解决方案

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 ++发生了什么,返回的值,但没有存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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