comp.lang.ada
 help / color / mirror / Atom feed
* My bug or compiler bug?
@ 2007-02-14 20:58 Anh Vo
  2007-02-15  0:44 ` Georg Bauhaus
  0 siblings, 1 reply; 3+ messages in thread
From: Anh Vo @ 2007-02-14 20:58 UTC (permalink / raw)


I could not understand why it, line 44 of the code below, compiles. I
strugged with the question why actual parameter R'(10.0, 20.0) matches
with access type parameter R_Pointer at line 15. Is it my bug or
compiler bug? Thanks.

AV

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

procedure Stream_IO_Demo_Cutdown is -- This is the cutdown version of
example
                                    -- Stream_IO_Demo in GNAT-GPL-2006
   type R is record
      A : Float;
      B : Long_Float;
   end record;

   type R_Pointer is access all R;

   procedure Write_R_Pointer
      (Stream : access Ada.Streams.Root_Stream_Type'Class;
       Item   : in     R_Pointer);
   for R_Pointer'Write use Write_R_Pointer;

   procedure Write_R_Pointer
      (Stream : access Ada.Streams.Root_Stream_Type'Class;
       Item   : in     R_Pointer)
      --  Write a boolean flag indicating whether Item designates an
object.
      --  If Item designates an object we also write the value of that
object.
   is
   begin
      if Item = null then
         Boolean'Write (Stream, False);
      else
         Boolean'Write (Stream, True);
         R'Write (Stream, Item.all);
      end if;
   end Write_R_Pointer;

begin

   Writing : declare
      File        : Stream_IO.File_Type;
      File_Stream : Stream_IO.Stream_Access;
   begin
      Stream_IO.Create (File, Stream_IO.Out_File, "Demo_Output");
      --  Get access to the stream representing the file.
      File_Stream := Stream_IO.Stream (File);

      Put_Line ("Writing record to file: (10.0, 20.0)");
      R'Write (File_Stream, R'(10.0, 20.0)); --# Why is OK while data
mismached
                                             --# with paramter at line
15
      Put_Line ("Writing integer to file: 2005");
      Integer'Write (File_Stream, 2005);

      --  We use the 'Output stream attribute to write both the value
of this
      --  unconstrained type as well as the constraint (in this case,
the array
      --  bounds).
      Put_Line ("Writing string to file: ""Hello World!""");
      String'Output (File_Stream, "Hello World!");

      Put_Line ("Writing access value designating record (1.0, -1.0)
to file");
      R_Pointer'Write (File_Stream, new R'(1.0, -1.0));

      Stream_IO.Close (File);
   end Writing;

end Stream_IO_Demo_Cutdown;




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

* Re: My bug or compiler bug?
  2007-02-14 20:58 My bug or compiler bug? Anh Vo
@ 2007-02-15  0:44 ` Georg Bauhaus
  2007-02-15  2:22   ` Anh Vo
  0 siblings, 1 reply; 3+ messages in thread
From: Georg Bauhaus @ 2007-02-15  0:44 UTC (permalink / raw)


On Wed, 2007-02-14 at 12:58 -0800, Anh Vo wrote:
> I could not understand why it, line 44 of the code below, compiles. I
> strugged with the question why actual parameter R'(10.0, 20.0) matches
> with access type parameter R_Pointer at line 15. Is it my bug or
> compiler bug? Thanks.
> 

>    for R_Pointer'Write use Write_R_Pointer;
> 

>       R'Write (File_Stream, R'(10.0, 20.0)); --# Why is OK while data
> mismached

I think R'Write is just the standard 'Write, expecting
record components as usual. (Unlike R_Pointer'Write)



 -- Georg 





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

* Re: My bug or compiler bug?
  2007-02-15  0:44 ` Georg Bauhaus
@ 2007-02-15  2:22   ` Anh Vo
  0 siblings, 0 replies; 3+ messages in thread
From: Anh Vo @ 2007-02-15  2:22 UTC (permalink / raw)


On Feb 14, 4:44 pm, Georg Bauhaus <bauh...@arcor.de> wrote:
> On Wed, 2007-02-14 at 12:58 -0800, Anh Vo wrote:
> > I could not understand why it, line 44 of the code below, compiles. I
> > strugged with the question why actual parameter R'(10.0, 20.0) matches
> > with access type parameter R_Pointer at line 15. Is it my bug or
> > compiler bug? Thanks.
>
> >    for R_Pointer'Write use Write_R_Pointer;
>
> >       R'Write (File_Stream, R'(10.0, 20.0)); --# Why is OK while data
> > mismached
>
> I think R'Write is just the standard 'Write, expecting
> record components as usual. (Unlike R_Pointer'Write)
>
>  -- Georg

Thank you very much for pointing it. For some reason, may be after
6:00 PM syndrome, I was thinking R_Pointer'Write instead of R'Write.
AV




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

end of thread, other threads:[~2007-02-15  2:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-14 20:58 My bug or compiler bug? Anh Vo
2007-02-15  0:44 ` Georg Bauhaus
2007-02-15  2:22   ` Anh Vo

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