Article View: net.lang.c
Article #9520Re: functions that don't return
From: Ray Butterworth
Date: Wed, 08 Oct 1986 17:38
Date: Wed, 08 Oct 1986 17:38
37 lines
1867 bytes
1867 bytes
> 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.
Technical Details
Message-ID:
<193@watmath.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!watmath!rbutterworthReferences:
<584@hadron.UUCP> <86900070@haddock> <1216@bunker.UUCP> <147@bobkat.UUCP> <3705@umcp-cs.UUCP>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site watmath.UUCP Path: arc1-ca.pugleaf.net!utzoo!watmath!rbutterworth From: rbutterworth@watmath.UUCP (Ray Butterworth) Newsgroups: net.lang.c Subject: Re: functions that don't return Message-ID: <193@watmath.UUCP> Date: Wed, 8-Oct-86 13:38:02 EDT Article-I.D.: watmath.193 Posted: Wed Oct 8 13:38:02 1986 Date-Received: Thu, 9-Oct-86 04:13:42 EDT References: <584@hadron.UUCP> <86900070@haddock> <1216@bunker.UUCP> <147@bobkat.UUCP> <3705@umcp-cs.UUCP> Organization: U of Waterloo, Ontario Lines: 38