Re: [C++] Omitted return statement
From: Sumit Rajan (sumitrajan_at_myrealbox.com)
Date: Thu, 29 Apr 2004 09:04:31 +0530
"Gary Labowitz" <email@example.com> wrote in message
> One of my students overloaded the operator<< function for use on a
> UDT. His code did not include a return statement even though the
> header calls for an ostream& as the return type. The program works
> anyway for chained output. How can this be? If it's undefined
> behavior, are we just getting unlucky?
> Using g++ 3.2 on W2K box. (You may need to include cstdlib)
It is undefined behaviour according to 6.6.3/2:
"Flowing off the end of a function is equivalent to a return with no value;
this results in undefined behavior in a value-returning function."
So I guess that your student was just plain lucky.