comp.lang.ada
 help / color / mirror / Atom feed
* Problem with streams using 64-bit compiler
@ 2010-01-04 22:46 sjw
  2010-01-04 23:09 ` Ludovic Brenta
  0 siblings, 1 reply; 3+ messages in thread
From: sjw @ 2010-01-04 22:46 UTC (permalink / 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;



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

end of thread, other threads:[~2010-01-04 23:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-04 22:46 Problem with streams using 64-bit compiler sjw
2010-01-04 23:09 ` Ludovic Brenta
2010-01-04 23:41   ` sjw

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