6.8.6.4 The return statement

Previous Table of Contents "New C Standard" commentary

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

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

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

1802 A function may have any number of return statements.

1803 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.

1804 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)

1805 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).

1806 136) The return statement is not an assignment.

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

1808 The representation of floating-point values may have wider range or precision and is determined by FLT_EVAL_METHOD.

1809 A cast may be used to remove this extra range and precision.

Next

Created at: 2008-01-30 02:39:44 The text from WG14/N1256 is copyright © ISO