6.8.6.4 The return statement

Previous Table of Contents

1785 A return statement with an expression shall not appear in a function whose return type is void.

1786 A return statement without an expression shall only appear in a function whose return type is void.

1787 A return statement terminates execution of the current function and returns control to its caller.

1788 A function may have any number of return statements.

1789 If a return statement with an expression is executed, the value of the expression is returned to the caller as the value of the function call expression.

1790 If the expression has a type different from the return type of the function in which it appears, the value is converted as if by assignment to an object having the return type of the function.136)

1791 EXAMPLE In:


        struct s { double i; } f(void);
        union {
                struct {
                        int f1;
                        struct s f2;
                } u1;
                struct {
                        struct s f3;
                        int f4;
                } u2;
        } g;

struct s f(void) { return g.u1.f2; }

/* ... */ g.u2.f3 = f();

there is no undefined behavior, although there would be if the assignment were done directly (without using a function call to fetch the value).

1792 136) The return statement is not an assignment.

1793 The overlap restriction of subclause 6.5.16.1 does not apply to the case of function return.

Next

Created at: 2005-06-29 02:19:03 The text from WG14/N1124 is copyright © ISO