Value, value, who's got the value?

Doug Gwyn gwyn at smoke.BRL.MIL
Thu Apr 27 22:45:28 AEST 1989


In article <1044 at itivax.iti.org> scs at vax3.iti.org (Steve Simmons) writes:
>int	func2()
>{
>	int c = 3 ;
>	c ;
>}

>Several questions: why does the OS make a difference; why does
>System V get it 'right' (even tho the code is wrong); why do
>none of these flag func2 as having a syntax error?

The function value was whatever was accidentally in the return
register.

This is yet another case of fortuitous accidents and lack of
diagnostic ability in the compiler.  In this case, the error
is in not returning a value for the function; because of long
historical practice before "void" was introduced, int-valued
functions in old code are often used like we would currently
use void-valued functions.  Therefore the compiler deliberately
is silent about such an error.

However, there is no syntax error; "c;" is a valid albeit
useless statement.

Why are you posting these bugs, anyway?



More information about the Comp.lang.c mailing list