Help solve argument about default return type

mdivax1!cameron mdivax1!cameron
Sat Jul 7 01:57:11 AEST 1990


I've been having a discussion with a friend about the following
situation:

Given a function foo() which returns a double, and another function
bar() which calls foo() and assigns the result to a double variable -
but foo() is not declared in the file where bar() is found.

e.g.:

---- foo.c -----

double foo ()
{
	return (7.0);
}

---- bar.c -----

bar ()
{
	double x;
	
	x = foo ();
}

My understanding of c is that, when compiling bar.c, the compiler will
assume that foo() returns int, so it will implicitly cast the return
value to double before assigning it to x. Even if an int and a double
are the same size (usually not true), this will involve some kind of
conversion - so x will end up with a garbage value.

My friend says she tried this with her Lattice c compiler on the Amiga,
and it worked fine. She speculates that the linker somehow fixes up the
return value so it all works.

My opinion is that if her compiler is really doing this, it's
disobeying the semantics of c.

I've tried with the SunOS 4.0 compiler, and it produces the garbage
value (as expected (by me)).

Does anyone have any insight? Anyone got Lattice c on the Amiga who'd
like to try it?

Respond by email, if you want to save net bandwidth.

Thanks!

Rick Cameron		...{uunet, ubc-cs}!van-bc!mdivax1!cameron
Mobile Data Intl	+1 604 277 1511
Vancouver, BC



More information about the Comp.lang.c mailing list