what happends if nothing is returned?

Started by
45 comments, last by graveyard filla 20 years ago
high, say i have a funtion, called int Blah(x); now, insidee Blah looks like this:


int Blah(x)
{

if(x == 5)
return 5;

if(x == 10)
return 10;

}

now, obviously not all the control paths return a value, and the compiler will warn me of this. but what will happen if i do this? int z = Blah(7); so what will happen? will the universe instantly implode? or will something magical happen? im guessing some sort of garbage will get put into it, but im not sure. so what does really happen, and if the answer is "garbage", what kind of garbage? what does this garbage look like? thanks for any help
FTA, my 2D futuristic action MMORPG
Advertisement
It will most likely give you whatever was left over in the eax register.
what the hell does that mean?
FTA, my 2D futuristic action MMORPG
quote:Original post by graveyard filla
what the hell does that mean?


junk

-me
Umh, what´s eax register? :o
actually, I believe that most compilers will silently insert a ''return 0;'' at the end of the function in that case. If they don''t, then yes, you would get garbage.


(Stolen from Programmer One)
UNIX is an operating system, OS/2 is half an operating system, Windows is a shell, and DOS is a boot partition virus
quote:Original post by Mkk
Umh, what´s eax register? :o
AFAIK, there are 4 registers: eax, ebx, ecx, and edx. I don''t know their true purposes, but you use them in Assembly to do calculations.
Dragon88: Yea, I got zero as a return value when I did a little test app..


[edited by - Mkk on March 26, 2004 7:11:17 PM]
quote:Original post by Mkk
Umh, what´s eax register? :o


registers are small one, two or four byte peices of memory directly inside the processor. That makes them the fastest possible memory, and the most expensive. eax is one of these on an x86 chip that is used to store the return value in the C calling convention.

Lucas Henekswww.ionforge.com
quote:Original post by Mkk
Dragon88: Yea, I got zero as a return value when I did a little test app..


[edited by - Mkk on March 26, 2004 7:11:17 PM]


Did you make sure to load eax with a bogus value before returning?


(Stolen from Programmer One)
UNIX is an operating system, OS/2 is half an operating system, Windows is a shell, and DOS is a boot partition virus

This topic is closed to new replies.

Advertisement