Re: enum/flags list_values values




Torsten Schoenfeld wrote:

On Sat, 2008-01-05 at 07:44 +1100, Kevin Ryde wrote:
Is Glib::Type->list_values meant to give back the values from the enum
and flags entries, as well as the names?  (There's no significance in
the order of the returned list or anything, is there.)

While the values do seem to be returned in order, I still think it makes
sense to include the actual value in the hash.  So here's the same patch
with a test.  muppet, what do you think?


The order of the enum values doesn't really matter, because C code is free to
assign them any value, such as this pathological thing:

  enum Evil {
     ONE = 5,
     TWO = 4,
     THREE = 3,
     FOUR = 2,
     FIVE = 1
  };


From the original documentation it seems clear that the intent was to include
the values, for that very reason.  As for why they were left out?  Who knows,
it was probably either an oversight or a subtle attempt to convince people not
to worry about evil numeric tricks and just use the nice nicknames.


At any rate, there are some things that just aren't possible without those
values (such as including the enum value in numeric user data, as seen in a
previous thread), so i think the patch should go in.  Looks pretty good, too.


-- 
muppet <scott at asofyet dot org>




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]