comp.lang.ada
 help / color / mirror / Atom feed
From: sjw <simon.j.wright@mac.com>
Subject: Problem with streams using 64-bit compiler
Date: Mon, 4 Jan 2010 14:46:37 -0800 (PST)
Date: 2010-01-04T14:46:37-08:00	[thread overview]
Message-ID: <2330c1ab-7a97-4b1f-a92a-f20c15501101@b2g2000yqi.googlegroups.com> (raw)

While trying to build a 64-bit compiler for Mac OS X Snow Leopard, I
came across this undesirable behaviour: if the program (see end) is
compiled in 32-bit mode or in 64-bit mode with -O0 it works fine,
output is as expected:

$ ./streamy
 1234
'z'
 4.32100E-01
 4.32100E-01

If compiled in 64-bit mode with -O2, output is

$ ./streamy
1234
NUL
 0.00000E+00
 0.00000E+00

This is a readback problem, the data file has the same content in all
cases.

Can anyone with access to an x86_64 compiler (Mac OS X Leopard, or a
Linux, 4.4+) have a try and see what happens?

Thanks in advance,

--S

--------------------------------------------------
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Streams.Stream_IO;

procedure Streamy is

   type Kind is (I, C, F);

   type Item (Of_Kind : Kind := I) is record
      case Of_Kind is
         when I => I : Integer;
         when C => C : Character;
         when F => F : Float;
      end case;
   end record;

   File : Ada.Streams.Stream_IO.File_Type;

   use Ada.Streams.Stream_IO;

begin

   Create (File, Name => "test.dat");

   Reset (File, Mode => Out_File);
   Item'Output (Stream (File), Item'(I, 1234));
   Item'Output (Stream (File), Item'(C, 'z'));
   Item'Output (Stream (File), Item'(F, 0.4321));

   Reset (File, Mode => In_File);
   for N in 1 .. 3 loop
      declare
         It : constant Item := Item'Input (Stream (File));
      begin
         case It.Of_Kind is
            when I =>
               Put_Line (It.I'Img);
            when C =>
               Put_Line (It.C'Img);
            when F =>
               Put_Line (It.F'Img);
         end case;
      end;
   end loop;

   Reset (File, Mode => Out_File);
   Item'Write (Stream (File), Item'(F, 0.4321));

   Reset (File, Mode => In_File);
   declare
      Flt : Item (F);
   begin
      Item'Read (Stream (File), Flt);
      Put_Line (Flt.F'Img);
   end;

end Streamy;



             reply	other threads:[~2010-01-04 22:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-04 22:46 sjw [this message]
2010-01-04 23:09 ` Problem with streams using 64-bit compiler Ludovic Brenta
2010-01-04 23:41   ` sjw
replies disabled

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