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

[Freeciv-Dev] removing/replacing enum unit_type_id

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] removing/replacing enum unit_type_id
From: David Pfitzner <dwp@xxxxxxxxxxxxxx>
Date: Sat, 28 Aug 1999 17:34:29 +1000 (EST)

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 :-)

Regards,
-- David








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