comp.lang.ada
 help / color / mirror / Atom feed
* Discriminated record question
@ 2002-05-07 12:17 Mark Doherty
  2002-05-10  9:27 ` Emmanuel Briot
  0 siblings, 1 reply; 11+ messages in thread
From: Mark Doherty @ 2002-05-07 12:17 UTC (permalink / raw)


Why does the following raise a constraint error on the declaration of
'B'.

I would not expect the declarations of 'A' or 'B' to raise a
constraint error.

If the compiler is right what, is the subtle difference between them
that allows 'A' not to raise the constraint error.

I am using Rational 3.2 compiler (PowerPC and Sun Solaris)



procedure Test is
    type A_Type (Text_Size : Natural := 0) is
       record
            Text : String (1 .. 0);
        end record;
    A : A_Type;

    type B_Type (Text_Size : Natural := 0) is
        record
            Text : String (1 .. Text_Size);
        end record;

    B : B_Type;  

begin
    null;
end Test;



^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: Discriminated record question
@ 2002-05-07 12:45 Grein, Christoph
  2002-05-07 19:18 ` Randy Brukardt
  2002-05-08 10:10 ` Mark Doherty
  0 siblings, 2 replies; 11+ messages in thread
From: Grein, Christoph @ 2002-05-07 12:45 UTC (permalink / raw)



> From: Mark.Doherty@uk.thalesgroup.com (Mark Doherty)
> 
> Why does the following raise a constraint error on the declaration of
> 'B'.
> 
> procedure Test is
>     type A_Type (Text_Size : Natural := 0) is
>        record
>             Text : String (1 .. 0);
>         end record;
>     A : A_Type;

Text component is always empty here, whichever Text_Size you use, so all objects 
have the same (small) size.

> 
>     type B_Type (Text_Size : Natural := 0) is
>         record
>             Text : String (1 .. Text_Size);
>         end record;
> 
>     B : B_Type;  

I presume, Storage_Error is raised, not Constraint_Error as you claim.
Here Text component depends on Text_Size. You define an unconstrained object, so 
the discriminant can vary, therefore the compiler has to allocate the maximum 
size, which is Natural'Last - quite big I'd say.
(A different model could be implemented by implicitly allocating on the heap as 
much storage as is currently needed. But this model is rarely used - is it 
currently used at all by some compiler?)

So the difference is not so subtle...



^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: Discriminated record question
@ 2002-05-16  5:03 Grein, Christoph
  0 siblings, 0 replies; 11+ messages in thread
From: Grein, Christoph @ 2002-05-16  5:03 UTC (permalink / raw)


From: Jeffrey Carter <jrcarter@acm.org>
> This is a case of the compiler being "correct but irritating". This is
> related to compilers that are "correct but useless". In the latter case,
> saying "Thank you. Your compiler is correct, but is unsuitable for our
> needs. We are therefore evaluating other compilers for our project."
> generally gets the vendor to sing a different tune. If you can honestly
> say this to your vendor you may suddenly find yourself possessed of an
> update that raises Storage_Error. But since this is only irritating, not
> useless, it may not be worth the effort.

I very much like the Rational Apex system, but sometimes Rational people have the 
attitude of saying: "We know how to do it correctly, you blockhead..."



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

end of thread, other threads:[~2002-05-16  5:03 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-07 12:17 Discriminated record question Mark Doherty
2002-05-10  9:27 ` Emmanuel Briot
  -- strict thread matches above, loose matches on Subject: below --
2002-05-07 12:45 Grein, Christoph
2002-05-07 19:18 ` Randy Brukardt
2002-05-09  2:52   ` Robert Dewar
2002-05-09 20:29     ` Randy Brukardt
2002-05-08 10:10 ` Mark Doherty
2002-05-09  2:56   ` Robert Dewar
2002-05-15 15:34     ` Mark Doherty
2002-05-15 18:12       ` Jeffrey Carter
2002-05-16  5:03 Grein, Christoph

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