comp.lang.ada
 help / color / mirror / Atom feed
* What's wrong with this program?
@ 2002-06-07 22:04 Allison Greene
  2002-06-07 23:16 ` sk
  2002-06-08  3:00 ` Jeffrey Carter
  0 siblings, 2 replies; 4+ messages in thread
From: Allison Greene @ 2002-06-07 22:04 UTC (permalink / raw)



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:

[localhost:~/lexicon] wrg% gnatmake -v test_discriminant.adb

GNATMAKE 5.00w (20010924) Copyright 1995-2001 Free Software Foundation,
Inc.
  "test_discriminant.ali" being checked ...
  -> "test_discriminant.ali" missing.
gcc -c test_discriminant.adb
test_discriminant.adb:13:20: invalid constraint: type has no
discriminant
End of compilation
gnatmake: "test_discriminant.adb" compilation error
[localhost:~/lexicon] wrg% 

Q: What discriminant?  What am I doing wrong here?

-- 
-- Bill Greene



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: What's wrong with this program?
  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
  1 sibling, 0 replies; 4+ messages in thread
From: sk @ 2002-06-07 23:16 UTC (permalink / raw)


Hi, 

> Q: What discriminant?  What am I doing wrong here?


The statement 

> Instance: Tower (I => 5);

is using a discriminant declaration syntax, not
the syntax for assigning a default value to "Tower"


--  
-------------------------------------
-- Merge vertically for real address
-------------------------------------
s n p @ t . o
 k i e k c c m
-------------------------------------



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: What's wrong with this program?
  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
  2002-06-08  4:40   ` William R. Greene
  1 sibling, 1 reply; 4+ messages in thread
From: Jeffrey Carter @ 2002-06-08  3:00 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: What's wrong with this program?
  2002-06-08  3:00 ` Jeffrey Carter
@ 2002-06-08  4:40   ` William R. Greene
  0 siblings, 0 replies; 4+ messages in thread
From: William R. Greene @ 2002-06-08  4:40 UTC (permalink / raw)


In article <3D017333.25E98380@acm.org>, Jeffrey Carter
<jrcarter@acm.org> wrote:

> ... . Perhaps
> what you wanted was
> 
> Instance : Tower := (I => 5);

Yes, now that you've pointed it out, it is obvious :-) that I did leave
out the assignment operator.  Thanks.

-- 
-- Bill Greene



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-06-08  4:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2002-06-08  4:40   ` William R. Greene

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