Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2002:
[Freeciv-Dev] Re: PATCH change_specialist
Home

[Freeciv-Dev] Re: PATCH change_specialist

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: gregor@xxxxxxxxxxxxx
Cc: freeciv development list <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: PATCH change_specialist
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 29 Jan 2002 18:24:10 +0100
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Tue, Dec 18, 2001 at 12:04:36PM +0100, Raimar Falke wrote:
> On Tue, Dec 18, 2001 at 11:14:10AM +0100, Gregor Zeitlinger wrote:
> > On Tue, 18 Dec 2001, Raimar Falke wrote:
> > > If you move C code to Java you have to make also other transformations
> > > (like replacing strcpy, or the iterate macros). So this boolean
> > > problem is your smallest problem.
> > well, but it's one less and makes the code more appealing for Java coders.
> > 
> > > Exactly. And this is the problem.
> > >  boolean a;
> > >  int b = a;
> > > will not create an error (like java would). So the compiler can't use
> > > the extra information.
> > Ok. That's due to the lack of weak typing in C. I just did it that time to
> > see the response, and if you agree I'd be happy to replace int with
> > boolean everywhere. I'm convinced it will help readability. To lessen the
> > chance of assining a boolean to an int, we could use something like a
> > hungarian notation like bHasChanged instead of has_changed or say that has
> > and is are also boolean prefixes. See my next email on this.
> 
> I'm not convinced that it will help. If something like this is made it
> should allow the compiler to catch it. Something like Reinier's
> struct. But even with this I don't see the typical programming errors
> this will catch. Well there are function like could_unit_move_to_tile
> which should be cleaned up with an enum.

Today I came across splint (www.splint.org). Using this program I
think it would be sensible to introduce bool(ean). It has a lot of
other features, a good docu and there are people working on it.

Examples:

common/city.c:1199:59: Expression has undefined behavior (unconstrained
    function game_next_year used in left operand may set global variable
    game.year used in right operand): game_next_year(pcity->turn_last_built) <
    game.year

common/city.c: (in function is_city_center)
common/city.c:100:10: Return value type boolean does not match declared type
                         int: (city_x == (5 / 2)) && (city_y == (5 / 2))
common/city.c:589:48: Right operand of && is non-boolean (int):
    s < game.rgame.min_city_center_shield && is_city_center(x, y)
common/city.c:764:3: Assignment of boolean to int:
    city_auto_water = (is_city_center(x, y) && tile_t == type->irrigation_result
     && terrain_control.may_irrigate)

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "Using only the operating-system that came with your computer is just
  like only playing the demo-disc that came with your CD-player."


[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: PATCH change_specialist, Raimar Falke <=