3

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.

2 Answers 2

8

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This should probably be the accepted answer.
3

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;

1 Comment

A little verbose, but it gets the job done. Thanks a bunch!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.