comp.lang.ada
 help / color / mirror / Atom feed
From: "Bernd Ragutt" <BerndRagutt@csi.com>
Subject: Re: Stream_io / records with default discriminants
Date: 1999/02/14
Date: 1999-02-14T00:00:00+00:00	[thread overview]
Message-ID: <#8nPq9DW#GA.131@nih2naac.prod2.compuserve.com> (raw)
In-Reply-To: m3lni1b5i9.fsf@mheaney.ni.net


Matthew Heaney wrote...

>You must post the smallest fragment of compilable code that illustrates
>the behavior you observe.  Without code, we can only guess what is
>going on.

Here is the fragment of code.
The code runs with GNAT/NT; with Apex/AIX  I get an exception (constraint
error).

Thanks.

Bernd Ragutt
from Munich
----------------------
BerndRagutt@csi.com



###################

--  ************ Types
    ...
    subtype Lstring_Length is Natural range 0 .. 25;

    type Lstring (Len : Lstring_Length := 0) is
        record
            Str : String (1 .. Len) := (others => ' ');
        end record;

    type Test_Enumeration is (Eins, Zwei, Drei);

    type Test_Records
            (Indicator : Test_Enumeration := Test_Enumeration'First) is
        record
            case Indicator is
                when Eins =>
                    Eins_Int : Integer := 1;
                when Zwei =>
                    Zwei_String : Lstring;
                when Drei =>
                    Drei_Int : Integer := 3;
                    Drei_String : Lstring;
            end case;
        end record;
    ...
--  ***********
    ...
    function Input_From_Stream return Test_Records is
    begin
        return Test_Records'Input (Date_File_Stream);
    exception
        when Ada.Streams.Stream_Io.End_Error =>
            raise Eof;
    end Input_From_Stream;
    ...
--  ************

with Text_Io;
with Ada.Io_Exceptions;
with Ada.Tags;

procedure Record_Io.Test2 is

    use Ada;

    Test_Record1 : Test_Records (Indicator => Eins);
    Test_Record2 : Test_Records := (Eins, 321);

    Test_Record3 : Test_Records :=
       (Indicator => Drei, Drei_Int => 999, Drei_String => (4, "AbcD"));

    Test_Record4 : Test_Records :=
       (Indicator => Zwei, Zwei_String => (5, "vWXYz"));

begin
    Open_Stream;

    Output_To_Stream (Test_Record1);
    Output_To_Stream (Test_Record1);
    Output_To_Stream (Test_Record2);
    Output_To_Stream (Test_Record3);
    Output_To_Stream (Test_Record4);

    Reset_To_Instream;

    loop
        declare
        begin
            -- ***
     declare
                Readed_Record : Test_Records
                      := Input_From_Stream;
                     --################################
                      -- Constraint Error when reading Test_Record2
            begin
                Text_Io.Put_Line
                   (Test_Enumeration'Image (Readed_Record.Indicator) & "
readed");
            exception
                when Eof =>
                    Text_Io.Put_Line ("EoF!");
                    exit;
            end;
     -- ***
        exception
         ...
        end;
    end loop;
end Record_Io.Test2;










  reply	other threads:[~1999-02-14  0:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-02-14  0:00 Stream_io / records with default discriminants Bernd Ragutt
1999-02-14  0:00 ` Matthew Heaney
1999-02-14  0:00   ` Bernd Ragutt [this message]
1999-02-14  0:00     ` Nick Roberts
1999-02-15  0:00       ` robert_dewar
1999-02-17  0:00         ` Nick Roberts
1999-02-18  0:00           ` dennison
1999-02-14  0:00     ` robert_dewar
1999-02-14  0:00 ` David C. Hoos, Sr.
replies disabled

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