Passing functions in C
Karl Heuer
karl at haddock.ima.isc.com
Wed Mar 14 10:52:46 AEST 1990
In article <3243 at hcx1.SSD.CSD.HARRIS.COM> brad at SSD.CSD.HARRIS.COM (Brad Appleton) writes:
>[The function int foo() { int i; i = 10; } will, on some compilers,
>appear to have returned the value 10. Unreliable?]
Very. What you're actually getting is whatever happened to be left lying
around in the function-return-value register.
>Should the compiler catch the "missing return" or is that left strictly
>to lint?
As far as the language definition goes, there is no distinction between cc and
lint. This check is traditionally done only in lint because it generally
requires cross-module analysis to know whether the value that isn't returned
from foo() is actually being used anywhere.
If it *isn't* being used, then the code is legal but sloppy (it should be
declared "void"). This remains legal for for backward compatibility, and,
unfortunately, a lot of code continues to depend on it.
Karl W. Z. Heuer (karl at ima.ima.isc.com or harvard!ima!karl), The Walking Lint
More information about the Comp.lang.c
mailing list