From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,b863ca48c5b37b7,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!l53g2000cwa.googlegroups.com!not-for-mail From: "Anh Vo" Newsgroups: comp.lang.ada Subject: My bug or compiler bug? Date: 14 Feb 2007 12:58:02 -0800 Organization: http://groups.google.com Message-ID: <1171486682.699549.276940@l53g2000cwa.googlegroups.com> NNTP-Posting-Host: 209.225.226.209 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1171486691 20371 127.0.0.1 (14 Feb 2007 20:58:11 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 14 Feb 2007 20:58:11 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322; InfoPath.1),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: l53g2000cwa.googlegroups.com; posting-host=209.225.226.209; posting-account=JVr7Xg0AAAAI3MbuARxMmvWLmA7qdJMx Xref: g2news2.google.com comp.lang.ada:9330 Date: 2007-02-14T12:58:02-08:00 List-Id: 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;