Skip to main content
gamedev.net
🔒 Locked

return

Started by luasitdown 3 replies 450+ views
Original Post
luasitdown
luasitdown
TYPE * boo() { if ( isTrue ) { ....... } } if isTrue is false, what value is return? it seem it is different according to release build or debug build. is that true? what is result of below, and WHY?

D3DXVECTOR3 boo()
{
	if (0 )
	{
		return D3DXVECTOR3(0,0,0);
	}
}
int main(int argc, char* argv[])
{
	D3DXVECTOR3  f = D3DXVECTOR3(33,33,33);
	f = boo();
} 


MaulingMonkey
MaulingMonkey
Quote:
Original post by luasitdown
TYPE * boo()
{
if ( isTrue )
{
.......
}

}

if isTrue is false, what value is return?


Undefined.

Quote:
it seem it is different according to release build or debug build. is that true?


It's quite possible. It's also quite possible for it to just crash. That function is badly written, it should return something, or stop on an assert or throw an exception.
etothex
etothex
It will return garbage. And it will be very different between debug and release, and also between slightly different versions of almost the same program.
CTar
CTar
As MaulingMonkey said, it's undefined, so it could make your computer catch fire, format you drives, but it will most likely return garbage memory, and maybe even destroy the stack for other functions (use a pop to get the return value, but there is no matching push).
Skeleton_V@T
Skeleton_V@T
Quote:
Original post by luasitdown
TYPE * boo()
{
if ( isTrue )
{
.......
}

}


A good compiler will warn you something on the line: "Not all control paths return a value.".
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.