Search code examples
enumsvhdl

VHDL: Why is 'length not defined for enums?


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.


Solution

  • @Paebbels

    No one requested this for any of the previous revisions. By the way, the working group needs additional experienced users, such as yourself to participate. This will help ensure we get relevant work done for the next revision.

    This request is captured here: http://www.eda.org/twiki/bin/view.cgi/P1076/EnumAttributes

    Our twiki starts here: http://www.eda.org/twiki/bin/view.cgi/P1076/

    Current proposals are here: http://www.eda.org/twiki/bin/view.cgi/P1076/CollectedRequirements

    Meeting information is here: http://www.eda.org/twiki/bin/view.cgi/P1076/MeetingMinutes

    IEEE 1076 is an individual based working group and encourages participation of the VHDL community. There are no special membership requirements to participate. Help shape the next revision, join us.

    Jim Lewis 1076 WG Chair