functions that don't return

Ray Butterworth rbutterworth at watmath.UUCP
Thu Oct 9 03:38:02 AEST 1986


> But it is doing something specific: the close-brace, if reachable,
> is equivalent to `return;'.  I doubt that anyone would argue that
> 
>     double foo() {
>         return;
>     }
> 
> is correct.

The GCOS8 Lint complains that
Function "foo" has no return value
Function "foo" is defined to return a value
(I guess it doesn't really "argue" about it though.:-)

If you think the above definition of foo() should be considered
valid, then without looking at the source for foo, consider:

{
    extern double foo();
    auto double x;
    x=foo();
    foo();
    ...
}

The extern declaration is correct, and required.
The first call to foo() is obviously correct, while the second
is obviously incorrect (or at least it ignores the returned value).
In fact, the first is wrong and the second is correct.

If the function doesn't return a value, why would you want to
state explicitly what type of value it doesn't return?  Either
the return statement or the declaration is wrong, and one of them
should be changed to match the other.  Otherwise you confuse
people who use the function.  They see the "double foo()" in the
source or in the header file containing the extern reference and
expect the function to return a value.



More information about the Comp.lang.c mailing list