Re: [C++] Omitted return statement
From: Sumit Rajan (sumitrajan_at_myrealbox.com)
Date: 04/29/04
- Next message: Leor Zolman: "Re: C++ array declaration question"
- Previous message: Barry Schwarz: "Re: strtok help please?"
- In reply to: Gary Labowitz: "[C++] Omitted return statement"
- Next in thread: Chris \( Val \): "Re: [C++] Omitted return statement"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 29 Apr 2004 09:04:31 +0530
"Gary Labowitz" <glabowitz@comcast.net> wrote in message
news:3fqdndbgQoiizQ3dRVn-gg@comcast.com...
> 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.
Regards,
Sumit.
- Next message: Leor Zolman: "Re: C++ array declaration question"
- Previous message: Barry Schwarz: "Re: strtok help please?"
- In reply to: Gary Labowitz: "[C++] Omitted return statement"
- Next in thread: Chris \( Val \): "Re: [C++] Omitted return statement"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|