comp.lang.ada
 help / color / mirror / Atom feed
* Re: Discriminant as default initial value
@ 1997-03-30  0:00 Kees de Lezenne Coulande
  1997-03-30  0:00 ` Robert Dewar
  0 siblings, 1 reply; 17+ messages in thread
From: Kees de Lezenne Coulande @ 1997-03-30  0:00 UTC (permalink / raw)



Scott Renfro <srenfro@SIRINET.NET> wrote:

>I want to use a discriminant in a record as both a bound in the index
>constraint of a component declaration and as a default initial value.
>I'm not sure that this is allowed by the RM.
>
>The following example, while contrived, exhibits behavior that I
>definitely do not understand.  Using GNAT 3.09 for NT with Max defined
>before the Position Matrix, the component record is initialized as
>expected.  When Max is defined after the Position Matrix within the
>record, Max is initialized to a large value that is not even within the
>subtype's range.  No exception is raised.
>
>Is this expected behavior?  Is it permissible to use the same
>discriminant as both an index bound and a default initial value?  Should
>the behavior change when the order of declaration within the record
>changes?

Scott,
     I tried both versions of your example using GNAT 3.09 for OS/2, and
found no problems. Maybe it is just the Windows version of GNAT playing up
again.
                                 Kees de Lezenne Coulander
---------------------------------------------------------------------
  C.M. de Lezenne Coulander
  Amsterdam-Zuidoost
  The Netherlands
  E-mail: lezenne@compuserve.com

  Aircraft Development and Systems Engineering B.V.
  Schiphol-Rijk, The Netherlands
=====================================================================




^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: Discriminant as default initial value
@ 1997-04-02  0:00 Kees de Lezenne Coulande
  1997-04-02  0:00 ` Robert Dewar
  1997-04-02  0:00 ` Scott Renfro
  0 siblings, 2 replies; 17+ messages in thread
From: Kees de Lezenne Coulande @ 1997-04-02  0:00 UTC (permalink / raw)



I wrote:

<<Scott,
     I tried both versions of your example using GNAT 3.09 for OS/2, and
found no problems. Maybe it is just the Windows version of GNAT playing up
again.
                                 Kees de Lezenne Coulander>>

and Robert Dewar <dewar@MERV.CS.NYU.EDU> replied:

>No, it works fine in the windows version too. This was a very vague
>report,
>I paid little attention to it. If people think they have found a problem
>in GNAT, it should be properly written up, formatted according to the
>suggestions in gnatinfo.txt, and sent to report@gnat.com.
<snip>

     I know by now how you feel about these things. It is just that this
one intrigued me, because I had not encountered the use of a record
discriminant as the default value for a component before. I spent a couple
of minutes trying it out, found that it seemed to work, and decided that I
could just as well post the reply.
     At the end of last year I acquired a copy of Norman Cohen's magnum
opus, and I am slowly working through it by of a couple of pages a day. By
coincidence, just after posting the message, my daily dose brought me to
pages 381/382 where the allowable uses of discriminants are described. So,
although the original poster may not be any the wiser, I have certainly
learned something. And besides, it was the Easter weekend.
                              Kees de Lezenne Coulander
---------------------------------------------------------------------
  C.M. de Lezenne Coulander
  Amsterdam-Zuidoost
  The Netherlands
  E-mail: lezenne@compuserve.com

  Aircraft Development and Systems Engineering B.V.
  Schiphol-Rijk, The Netherlands
=====================================================================




^ permalink raw reply	[flat|nested] 17+ messages in thread
* Discriminant as default initial value
@ 1997-03-29  0:00 Scott Renfro
  1997-03-29  0:00 ` Matthew Heaney
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Scott Renfro @ 1997-03-29  0:00 UTC (permalink / raw)



Greetings,

I'm new to Ada and have scoured the FAQ, RM, and Rationale, but haven't
found an answer to my question that I understand.

I want to use a discriminant in a record as both a bound in the index
constraint of a component declaration and as a default initial value. 
I'm not sure that this is allowed by the RM.

The following example, while contrived, exhibits behavior that I
definitely do not understand.  Using GNAT 3.09 for NT with Max defined
before the Position Matrix, the component record is initialized as
expected.  When Max is defined after the Position Matrix within the
record, Max is initialized to a large value that is not even within the
subtype's range.  No exception is raised.

Is this expected behavior?  Is it permissible to use the same
discriminant as both an index bound and a default initial value?  Should
the behavior change when the order of declaration within the record
changes?

Thanks in advance,
Scott

-----------------------------------------------------
--
-- Test_Discrim.adb
--
-----------------------------------------------------
with Ada.Text_IO, Ada.Command_Line;
use  Ada.Text_IO;

procedure Test_Discrim is

   type Matrix is array (Integer range <>, Integer range <>) of Integer;
   subtype Matrix_Range is Natural range 1 .. 80;
   
   type Matrix_Record (Columns : Matrix_Range) is
      record
--         Max      : Natural := Columns;   -- if declared here, all is
well
         Position : Matrix (1 .. Columns, 1 .. Columns);
         Max      : Matrix_Range := Columns;   -- if declared here, max
improper
      end record;

   width : Matrix_Range := 1;
   
begin
   width := Integer'value (Ada.Command_Line.Argument (1));
   declare
      Temp_Matrix : Matrix_Record (Width);
   begin
      Put_Line (Integer'Image (Temp_Matrix.Max));
   end;
end test_discrim;




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

end of thread, other threads:[~1997-04-07  0:00 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-03-30  0:00 Discriminant as default initial value Kees de Lezenne Coulande
1997-03-30  0:00 ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1997-04-02  0:00 Kees de Lezenne Coulande
1997-04-02  0:00 ` Robert Dewar
1997-04-07  0:00   ` Keith Thompson
1997-04-02  0:00 ` Scott Renfro
1997-04-02  0:00   ` Robert Dewar
1997-03-29  0:00 Scott Renfro
1997-03-29  0:00 ` Matthew Heaney
1997-03-30  0:00   ` Scott Renfro
1997-03-30  0:00 ` Bob Klungle
1997-03-30  0:00   ` Robert Dewar
1997-03-31  0:00     ` Bob Klungle
1997-03-31  0:00       ` Robert Dewar
1997-03-31  0:00 ` Jon S Anthony
1997-03-31  0:00   ` Robert Dewar
1997-04-02  0:00   ` Jon S Anthony

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