Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

function return not assigned to a variable

What if you call a (non-void) function, but don't assign its return value to a variable? e.g., getchar();

I've always wondered what happens to such a value. I've heard humorous explanations like "its gone to the ether" and so forth, but I'd really like to know really. Would there be any way to recover such a value? Thanks

like image 477
Bill Avatar asked Jul 07 '10 20:07

Bill


1 Answers

This is really compiler / CPU specific, but in most cases the return value will be in a CPU register (if it will fit), and if that register is not touched by the subsequent code, you could retrieve it using e.g. "inline assembler".

To answer your question better, nothing "happens" to the value. It sits in a stack-location or inside a register. If you use it, fine... if not, nothing happens really. Eventually the stack or register is overwritten by new values...

like image 54
S.C. Madsen Avatar answered Sep 21 '22 12:09

S.C. Madsen