I have the following enum declaration:
type T_STATUS is ( -- position / index
STATUS_INIT, -- pos = 0
STATUS_RECONFIGURING, -- pos = 1
STATUS_RELOADING, -- pos = 2
STATUS_READY, -- pos = 3
STATUS_ERROR -- pos = 4
);
Why is it not possible to use T_STATUS'length
to get the count of T_STATUS
members?
Example code:
constant Count : POSITIVE := T_STATUS'length;
Workaround:
It's possible to get that number by using T_STATUS'high
and T_STATUS'pos
as follows:
constant Count : POSITIVE := T_STATUS'pos(T_STATUS'high) + 1;
This works, because 'high
gives the last enum member and 'pos
converts this member into it's position in the enum list. Because the positions start at 0, one must add 1 to get the correct count/length.
Update:
'length
and lots of other features have been added by me into the VHDL standard. Starting from VHDL-2019, it's now supported to get the number of elements in an enumeration type. See the IEEE Std. 1076-2019 or http://www.eda-twiki.org/cgi-bin/view.cgi/P1076/VHDL2017 for more details and other similar changes.