Re: [sv-bc] enum.num method

From: Rishiyur S. Nikhil <nikhil_at_.....>
Date: Tue Aug 23 2005 - 10:39:18 PDT
An analogy might be the sizeof() operator in C/C++,
which can be applied to a type or to an expression;
in the latter case, it gives the size of the type of the
expression.

Nikhil

Paul Graham wrote:
> 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 10:39:25 2005

This archive was generated by hypermail 2.1.8 : Tue Aug 23 2005 - 10:39:38 PDT