From: "Anh Vo" <anhvofrcaus@gmail.com>
Subject: My bug or compiler bug?
Date: 14 Feb 2007 12:58:02 -0800
Date: 2007-02-14T12:58:02-08:00 [thread overview]
Message-ID: <1171486682.699549.276940@l53g2000cwa.googlegroups.com> (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;
next reply other threads:[~2007-02-14 20:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-14 20:58 Anh Vo [this message]
2007-02-15 0:44 ` My bug or compiler bug? Georg Bauhaus
2007-02-15 2:22 ` Anh Vo
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox