[sv-bc] enum.num method

From: Paul Graham <pgraham_at_.....>
Date: Tue Aug 23 2005 - 09:25:22 PDT
The num() method for enumeration types is a bit confusing to
use:

    typedef enum {red, blue, green} color;

    y = red.num;

Here, the expression red.num has nothing to do with the enum
literal red.  Instead it returns a property of type color.
In contrast, the other enum methods all return properties
of their enum value arguments.  I think you'd want to write:

    y = color.num;

but I don't think that a type name is allowed as a
method_call_root.

I wonder if something like the vhdl 'pos and 'val attributes
would be useful:

    function int pos()	

    returns the position (indexed from 0) of the enum
    literal in the type.

    function enum val(unsigned int N)

    returns the value of the N'th position of the enum type

So:

    red.pos() == 0
    red.val(2) == green		// looks funny to me
    color.val(2) == green	// better...


Paul
Received on Tue Aug 23 09:25:24 2005

This archive was generated by hypermail 2.1.8 : Tue Aug 23 2005 - 09:25:44 PDT