FWD: Re: GHC FFI Return Type Bug

Fergus Henderson fjh@cs.mu.oz.au
Wed, 8 Aug 2001 18:56:05 +1000


Sigbjorn Finne <sof@galconn.com> wrote:
> 
> "Julian Seward (Intl Vendor)" <v-julsew@microsoft.com> writes:
> > 
> > | > char fooble ( ... )
> > | > {
> > | >    return 'z';
> > | > }
> > | > 
> > | > on an x86, 'z' will be returned at the lowest 8 bits in %eax. What I
> > | > don't know is, is the C compiler obliged to clear the upper 24 bits of
> > | > %eax, or does that onus fall on the callee?

The upper 24 bits of eax must be cleared in the callee.
The caller can assume that they are zero.

I don't know if this is documented anywhere, but that is the convention
which GNU C follows (on all architectures -- the C front-end internally
promotes the return type from "char" to "int").  I can point you to
the exact line of code in the GNU C front-end if you really want.

I think this is required by traditional K&R C code, which does things
like calling such functions without declaring them.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.