Reputation: 321
Say I have a type
type Record_T is
record
VAR1 : integer := 1;
VAR2 : string := "";
end record;
If I want to initialize a constant variable of this type, I can do it a few ways:
Null_Record : constant Record_T := (1, "");
Null_Record : constant Record_T := Record_T'(1, "");
but this forces me to specify the default values, when I already previously specified them.
I've tried all of the following, to no avail
Null_Record : constant Record_T := ();
Null_Record : constant Record_T := Record_T'();
Null_Record : constant Record_T;
But there has to be some way to do so? At least, I'd be very surprised if Ada lacked that capability.
Upvotes: 3
Views: 1333
Reputation: 3358
The typical way, pre-ISO/IEC 8652:2007, presuming your type is in a package, is to declare a deferred constant in the visible part:
Null_Record : constant Record_T;
and then complete it in the private part with:
Null_Var : Record_T;
Null_Record : constant Record_T := Null_Var;
Upvotes: 3
Reputation: 321
It looks like this should be possible in Ada 2005, using the new "default value initialization" for aggregates using the <>
operator.
This would look something like
Null_Record : constant Record_T := (others => <>);
I can't see any way to do this pre-Ada 2005. Unfortunately, this isn't a solution for me, being stuck with Ada 95.
Upvotes: 8