Complete.Org: Mailing Lists: Archives: freeciv-dev: August 1999:
Re: [Freeciv-Dev] removing/replacing enum unit_type_id
Home

Re: [Freeciv-Dev] removing/replacing enum unit_type_id

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: David Pfitzner <dwp@xxxxxxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: Re: [Freeciv-Dev] removing/replacing enum unit_type_id
From: Jerzy Klek <qpkjeek@xxxxxxxxxxxxxxx>
Date: Mon, 30 Aug 1999 11:48:11 +0200 (MET DST)

> Now that the enum unit_type_id does not really enumerate the
> unit types (due to rulesets, and variable number of unit types)
> I would like to remove/replace the enum, as previously mentioned.
> 
> I was going to do:
>    typedef unsigned char Unit_Type_id;
> and simple replace all instances of 'enum unit_type_id' with
> Unit_Type_id.  The reason for using an unsigned char is that
> all valid unit_type_id values should fit in an unsigned char
> (enforced by sending ids as 8-bit ints in packets).
> 
> But, there are some complications, mainly:
> 
> 1.  In a few cases, the value -1 is used as a "flag" value 
> for something which is nominally a unit type id.  Eg, 
> obsoleted_by is the main case, but there are one or two 
> others.
> 
> This may or may not cause problems:
> 
> - I _think_ all such cases already use plain 'int' rather
> than actual 'enum unit_type_id', in which case it won't 
> matter.
> 
> - If -1 were consistently cast to (enum unit_type_id), or
> now (Unit_Type_id), it would make consistent sense.  But I
> don't think it is, neither explicitly nor implicity, since
> as noted above mostly plain 'int' is used.
> 
> - Ideally, U_LAST should probably have been used as the flag
> value, as it is in other cases.  These cases with -1 could 
> be changed to use U_LAST.
> 
> Another possible issue:
> 
> 2. Using plain 'int' may be more efficient.  (On the other
> hand 'unsigned char' _may_ be more space efficient, but in
> practice probably not due to alignment/padding, or negligible
> in any case.)  
> 
> So maybe should make the typedef to just an 'int'. 
> Or simply replace 'enum unit_type_id' in the code with 
> 'int', although I rather prefer a typedef, as it helps
> make the code a bit more self-documenting.
> 
> Any opinions?  (on this possibly trivial/pedantic matter :-)

I have the same problem now, as I started thinking about having
changeable number of nations. I think it is good to use a
typedef for the code to be more explanatory. I think doing
typedef int unit_type_id will be good to avoid -1 problem.
Wll whatever you decide, let me know, I want to have
nation_type_id look the same, just for the sake of
consistency :-)

Jerzy




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