Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2004:
[Freeciv-Dev] Re: contains_special type safe?
Home

[Freeciv-Dev] Re: contains_special type safe?

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Cc: Freeciv-Dev <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: contains_special type safe?
From: Jason Dorje Short <jdorje@xxxxxxxxxxxx>
Date: Sun, 16 May 2004 02:05:04 -0400

Mike Kaufman wrote:
/***************************************************************
 Returns TRUE iff the given special is found in the given set.
***************************************************************/
bool contains_special(enum tile_special_type set,
                      enum tile_special_type to_test_for)
{
  enum tile_special_type masked = set & to_test_for;

  assert(0 == (int) S_NO_SPECIAL);

  /*
   * contains_special should only be called with one S_* in
   * to_test_for.
   */
  assert(masked == S_NO_SPECIAL || masked == to_test_for);

  return masked == to_test_for;
}

surely this can't be correct: enum tile_special_type set is in general not
an enum tile_special_type...

True, but this kind of thing is common. The most obvious alternative is using an int for the 'set' but this is just as bad. A typedef is possible (typedef int special_set) but not much better.

The only "good" alternative is a BV_DEFINE. This would mean changing the enum so it's no longer a bitmask and making the "set" a bitvector.

jason


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