This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
missing return statement
- From: Nathan Ridge <zeratul976 at hotmail dot com>
- To: <gcc at gcc dot gnu dot org>
- Date: Thu, 12 Mar 2009 23:42:23 +0000
- Subject: missing return statement
Hello,
So many times I write code like this:
SomeType function()
{
SomeType result;
// do something with result
return result;
}
except I often forget the "return result" statement.
Why does gcc not give an error about this?
If I compile with "-Wall", it will give a WARNING saying
"control reaches end of non-void function".
However, shouldn't it be an ERROR to return nothing
from a function that's supposed to return something?
Does this not result in undefined behaviour? Why goes gcc allow it?
Thanks,
Nate.
_________________________________________________________________
Share photos with friends on Windows Live Messenger
http://go.microsoft.com/?linkid=9650734