Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Uncle George <gatgul@voicenet.com>
To: axp-list@redhat.com
Cc: Dan Morrill <morrildl@nycap.rr.com>, Richard Henderson <rth@twiddle.net>
Subject: Re: Function parameter weirdness
Date: Fri, 29 Oct 1999 06:28:26 -0400	[thread overview]
Message-ID: <381976CA.EF859700@voicenet.com> (raw)
In-Reply-To: 19991028163857.C27836@twiddle.net

Ok,
    "sign extend all 32bit integers"  ( I dont think this is in k&r ) . what
of Sign extening "short"s? "char"s ? by the caller.

    But all this is related to the fact the the 'C" compiler really doesn't
know what the function parameters are at time of compile/link binding. they
are only known at runtime ( this is true for java/JNI, but not for
postgreSQL )  There is just one ( JNI ) interface to all of the
subroutines.  And apparently it, as well as the guy who writes the JNI
interface needs to know the 'tricks' of this machine's trade.


SOoooo By ur example:

        unsigned short a = 0xffff;
        call foo( a );
..............

        foo( short a )
            if ( a == -1 ) printf("Got a neg one");
            else                printf("Got bogus value");

In the land of the i386 i'd guess u'd "got a neg one", according to u u
would get a 65536 ( or was that 65535 ) value  Even though the # & pattern
of bits are =, the alpha will do a 64 bit compare, whereas ( i suspect ) the
i386 will do a (expected) 16bit ( signed ) compare.

Richard Henderson wrote:

> On Mon, Oct 25, 1999 at 06:19:13AM -0400, Uncle George wrote:
> > yup, but it sppears that the 'sender' of the parameter has to know what
> > type it is to get this picture correct.
>
> Kindof.  The caller is supposed to sign-extend all 32-bit integers.
> Note that this is without respect to whether the variable is declared
> as `unsigned int' in the source.
>
> Values smaller than `int' are promoted by K&R rules to `int', so eg
> `unsigned short' winds up zero extended since bit 31 is never set.
>



      reply	other threads:[~1999-10-29 10:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-10-24  3:03 Function parameter weirdness Dan Morrill
1999-10-24 15:03 ` Uncle George
1999-10-24 20:18   ` Dan Morrill
1999-10-25 10:19     ` Uncle George
1999-10-28 23:38       ` Richard Henderson
1999-10-29 10:28         ` Uncle George [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox