FWD: Re: GHC FFI Return Type Bug
Fergus Henderson
fjh@cs.mu.oz.au
Thu, 9 Aug 2001 12:20:50 +1000
On 08-Aug-2001, Fergus Henderson <fjh@cs.mu.oz.au> wrote:
> 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.
On further investigation it appears that although what I wrote is true
for GNU C, it seems to *not* be true for GNU C++, which was being used in
the code in the original bug report.
I'm not sure why that is. The C++ front-end has some code similar to
the code in the GNU C front-end, to promote function return types,
but the code seems to not get used. I don't know whether that is
deliberate or not.
--
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.