Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2004:
[Freeciv-Dev] Re: (PR#9899) Assertion failed: cont > 0, file improvement
Home

[Freeciv-Dev] Re: (PR#9899) Assertion failed: cont > 0, file improvement

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: brett.albertson@xxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#9899) Assertion failed: cont > 0, file improvement.c, line 289
From: "Benoit Hudson" <bh@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 1 Sep 2004 22:12:30 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9899 >

On Wed, Sep 01, 2004 at 09:53:04PM -0700, Jason Short wrote:
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=9899 >
> I knew something like this was going to happen.  Fixing it is neither
> easy nor pretty...
>
> We should never do casting.  dio_get_uint8 should take a uint8*, not an
> int*.
>
> One question is how can we be guaranteed of uint8, sint16, etc., values?
> Probably we should declare these types.  Using autoconf support we can
> often import them from the system headers.  On some platforms
> sizeof(short) != 2 (I'm told) so making things portable will require
> some autoconf work.

Question: why does dio take an int* rather than returning int?  If we
just made it return int, everything would be peachy.

Ultimately I agree that we should use int16 etc rather than short: short
means someone is making an assumption that the value is never going to
be larger than 16 bits, but might conceivably be larger than 8.  That
assumption should be explicit.

If we do this, making dio take the correct thing by reference would give
us some better type-checking than just returning int.

Fixing this shouldn't be too hard once we do the configury:
    find . -name *.[ch] | xargs perl -pi 's/unsigned short/uint16'
    find . -name *.[ch] | xargs perl -pi 's/short/uint16'
and so on.

Enums pose a special problem all their own.  I don't see how we can do
anything with them but:
        int tmp;
        dio(&tmp);
        myenum = tmp
solution.

        -- Benoît




[Prev in Thread] Current Thread [Next in Thread]