comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <jrcarter@acm.org>
Subject: Re: What's wrong with this program?
Date: Sat, 08 Jun 2002 03:00:12 GMT
Date: 2002-06-08T03:00:12+00:00	[thread overview]
Message-ID: <3D017333.25E98380@acm.org> (raw)
In-Reply-To: 070620021804210406%argreene@usanospam.net

Allison Greene wrote:
> 
> procedure Test_Discriminant is
>    type Base is tagged null record;
> 
>    type Tower is new Base with
>       record
>          I : Integer;
>       end record;
> 
>    Instance: Tower (I => 5);
> begin
>    null;
> end Test_Discriminant;
> 
> Result of compiling with GNAT:
> 
> test_discriminant.adb:13:20: invalid constraint: type has no
> discriminant

The error message is quite clear: You are attempting to provide a
discriminant constraint to a type that has no discriminant.

The declaration

type Tower (I : Integer) is record
   F : Float;
end record;

declares a type with a discriminant (I). You would declare an object of
this type with

Instance : Tower (I => 5);

which is exactly the syntax you used. For your declaration of type
Tower, this is illegal, since it does not have a discriminant. Perhaps
what you wanted was

Instance : Tower := (I => 5);

which creates the object and initializes it with the value to the right
of ":=". Since Tower is a record type, that value is a record aggregate.

-- 
Jeff Carter
"Your mother was a hamster and your father smelt of elderberries."
Monty Python & the Holy Grail



  parent reply	other threads:[~2002-06-08  3:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-07 22:04 What's wrong with this program? Allison Greene
2002-06-07 23:16 ` sk
2002-06-08  3:00 ` Jeffrey Carter [this message]
2002-06-08  4:40   ` William R. Greene
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox