Re: [AD] Borland C++ compilation errors

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Mon, Nov 05, 2001 at 02:19:18PM +0100, Eric Botcazou wrote:
> > Surely that function now always returns 0x7FFF?
> 
> Oh My God ! (tm) You're right.
> 
> > Assuming `fixed' is still `int',
> 
> 'long' actually.
> 
> I (unconsciously) didn't feel very comfortable with this tiny patch, now I
> know why... I hope the attached one is right :-)

>  AL_INLINE(int, fceil, (fixed x),
>  {
>     x += 0xFFFF;
> -   if (x >= 0x80000000) {
> +   if ((unsigned long)x >= 0x80000000) {
>        *allegro_errno = ERANGE;
>        return 0x7FFF;
>     }

Hmm... but this still doesn't work for negative inputs (they'll
always cast to unsigned longs greater than the test value).  You
really need to do this check before adding 0xFFFF, i.e.:

    AL_INLINE(int, fceil, (fixed x),
    {
        if (x >= (long)(0x80000000 - 0xFFFF)) {
            *allegro_errno = ERANGE;
            return 0x7FFF;
        }
        x += 0xFFFF;

George



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/