Reputation: 1223
Is it possible to define a default value for a record type or generally any user defined type?
Something like (pseudo VHDL):
type t_foo is record
a : integer := 4;
b : std_logic := '0';
end record;
or
subtype glarp is integer range 0 to 10 := 5;
EDIT: changed glarp from type to subtype definition.
Upvotes: 4
Views: 3117
Reputation: 1223
I take the liberty of turning a comment into an answer. The initial value for a record type could be defined by a constant of that type.
type t_foo is record
a : integer;
b : std_logic;
end record;
constant INIT_T_FOO : t_foo := (a => 4, b => '0');
signal bar : t_foo := INIT_T_FOO;
A downside of this approach is that the user has to ensure the correct initial value is set every time an object of type t_foo
is defined. Using a constant to define an initial value can save some typing and makes it easier to change the initial value later. But again, it is not possible to enforce a specific initial value this way, it all comes down to coding discipline and human error, thus it's a suboptimal solution.
Upvotes: 2