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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,6339fea48a1b8cda X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!c65g2000hsa.googlegroups.com!not-for-mail From: richtmyer@cox.net Newsgroups: comp.lang.ada Subject: Re: Enumeration representation clause surprise. Date: Thu, 12 Jun 2008 12:05:05 -0700 (PDT) Organization: http://groups.google.com Message-ID: <770ae1af-b9fd-4c8a-915c-a5cb3ea8fc81@c65g2000hsa.googlegroups.com> References: NNTP-Posting-Host: 164.223.72.5 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1213297506 4900 127.0.0.1 (12 Jun 2008 19:05:06 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 12 Jun 2008 19:05:06 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c65g2000hsa.googlegroups.com; posting-host=164.223.72.5; posting-account=Z7Cz1woAAAA0DPjSZK8wuaYD_ro5RKkK User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.0.04506.30),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:676 Date: 2008-06-12T12:05:05-07:00 List-Id: On Jun 11, 7:38=A0am, Markus Schoepflin wrote: > Hello, > > please consider the following code snippet: etc ----- Interesting. I had been playing with a similar example, and have modified it a bit to present. What got me is the record type with length 1 but an object with that type that was length zero! (It compiles without any warnings). ------------------------------ test1.2.ada -------------------------------------- -- -- GPS 4.2.1 (20080115) hosted on pentium-mingw32msv -- GNAT GPL 2007 (20070405-41) -- -- X_Type'size =3D 31 -- X_Rec_Type'size =3D 32 -- X_Rec'size =3D 32 -- Y_Rec_Type'size =3D 1 -- Y_Rec'size =3D 8 -- X_Rec.X1 =3D 2147483647 -- Y_Rec.X1 =3D 2147483647 -- GPS Pro 4.1.1 (20070423) hosted on i686-pc-linux-gnu -- GNAT Pro 6.1.1 (20080111-41) -- -- X_Type'size =3D 31 -- X_Rec_Type'size =3D 32 -- X_Rec'size =3D 32 -- Y_Rec_Type'size =3D 1 -- Y_Rec'size =3D 0 -- this object is smaller than its type! -- X_Rec.X1 =3D 2147483647 -- Y_Rec.X1 =3D 2147483647 ------------------------------------------------------------------------- with ada.exceptions; use ada.exceptions; with interfaces.c; with text_io; use text_io; with unchecked_conversion; procedure test1 is type X_Type is ( X ); for x_type use (x =3D> 16#7FFF_FFFF#); type X_Rec_Type is Record X1 : X_Type; End Record; X_Rec : X_Rec_Type :=3D (X1 =3D> x); type Y_Rec_Type is Record X1 : X_Type; End Record; for Y_Rec_Type'size use 0; for Y_Rec_Type use Record X1 at 0 range 0 .. -1; -- Minus 1 !! End Record; Y_Rec : Y_Rec_Type :=3D (X1 =3D> X); function convert is new unchecked_conversion (X_type, natural); begin put_line("X_Type'size =3D " & X_Type'size'img); put_line("X_Rec_Type'size =3D " & X_Rec_Type'size'img); put_line("X_Rec'size =3D " & X_Rec'size'img); put_line("Y_Rec_Type'size =3D " & Y_Rec_Type'size'img); put_line("Y_Rec'size =3D " & Y_Rec'size'img); put_line("X_Rec.X1 =3D " & convert(X_Rec.X1)'img); put_line("Y_Rec.X1 =3D " & convert(Y_Rec.X1)'img); end test1;