g++ - Omitting return statement in C++ -
There was some strange behavior from the version of g ++ for Windows that I found with strawberry pearl. This allowed me to leave a return statement.
I have a member task that gives a structure consisting of two points, which is called boundTag
:
straight bound tag box :: Getbound (int side) {struct boundTag retBoundTag; RetBoundTag.box = this; Set (bound) set // based on the value of "bound" set bounded. Bound)}}
This function gave me some poor output, and I found out that no returns Not a statement I meant to return retBoundTag
but really forgot to write back statement Everything was fine.
But I tested this function and got the correct boundTag
output from it. Even now, when I remove the return statement, G ++ collects it without warning WTF? Whether return
return
Functions use [without main
] and the returned value in your code.
ISO C ++ - 98 [section 6.6.3 / 2]
A return statement with an expression can only be used in returning a value is; The value of the expression is returned to the caller of the function. If necessary, the expression changes in the return type of the function in which it appears. The return statement may include the creation and copy of a temporary object ( class.temporary ). Returns at the end of a function with a return value;
For example
int func ()) contains undefined behavior {int a = 10; // Do something with 'A' / oops no return statement} int main () {int p = func (); // is dangerous using // return statement here is optional}
Generally G ++ gives a warning: the control reaches the end of the non-zero function Try compiling it with the
-Wall
option.
Comments
Post a Comment