I have multiple inputs that belong together(get sampled at the same clock etc.) but are not logically a vector(i.e. not a parallel bus) in a piece of existing code I need to modify.
Previously, they were defined as
type my_type is array (my_width - 1 downto 0) of std_logic;
signal my_signal : my_type;
Until now, for this purpose, I always used this:
subtype my_subtype is std_logic_vector(my_width - 1 downto 0);
signal my_signal : my_subtype;
For most intentions and purposes, an array and a vector can be handled pretty much the same, so my question is:
Is there any advantage to either way of doing things? Is there a preferred/standard way?
There is a difference, which has to do with strong typing.
With your first piece of code, you create a new type. It is independent and not compatible with other types. Just consider the next piece of code:
When compiling in modelsim, this code will give errors:
For the second piece of code, the underlying type is still a
std_logic_vector
. Thus the subtypes are compatible. Consider the next piece of code:This does compile (i.e. no errors).