comp.lang.ada
 help / color / mirror / Atom feed
From: richtmyer@cox.net
Subject: Re: Enumeration representation clause surprise.
Date: Thu, 12 Jun 2008 12:05:05 -0700 (PDT)
Date: 2008-06-12T12:05:05-07:00	[thread overview]
Message-ID: <770ae1af-b9fd-4c8a-915c-a5cb3ea8fc81@c65g2000hsa.googlegroups.com> (raw)
In-Reply-To: g2odf9$3um$1@nntp.ilk.net

On Jun 11, 7:38 am, Markus Schoepflin <nos...@no.spam> 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     =  31
--  X_Rec_Type'size =  32
--  X_Rec'size      =  32
--  Y_Rec_Type'size =  1
--  Y_Rec'size      =  8
--  X_Rec.X1        =  2147483647
--  Y_Rec.X1        =  2147483647

--  GPS Pro 4.1.1 (20070423) hosted on i686-pc-linux-gnu
--  GNAT Pro 6.1.1 (20080111-41)
--
--  X_Type'size     =  31
--  X_Rec_Type'size =  32
--  X_Rec'size      =  32
--  Y_Rec_Type'size =  1
--  Y_Rec'size      =  0             -- this object is smaller than
its type!
--  X_Rec.X1        =  2147483647
--  Y_Rec.X1        =  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 => 16#7FFF_FFFF#);

   type X_Rec_Type is
      Record
        X1 : X_Type;
      End Record;

   X_Rec : X_Rec_Type := (X1 => 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 := (X1 => X);

   function convert is new unchecked_conversion (X_type, natural);
begin

   put_line("X_Type'size     = " & X_Type'size'img);
   put_line("X_Rec_Type'size = " & X_Rec_Type'size'img);
   put_line("X_Rec'size      = " & X_Rec'size'img);
   put_line("Y_Rec_Type'size = " & Y_Rec_Type'size'img);
   put_line("Y_Rec'size      = " & Y_Rec'size'img);
   put_line("X_Rec.X1        = " & convert(X_Rec.X1)'img);
   put_line("Y_Rec.X1        = " & convert(Y_Rec.X1)'img);

end test1;




  parent reply	other threads:[~2008-06-12 19:05 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-11 11:38 Enumeration representation clause surprise Markus Schoepflin
2008-06-11 12:30 ` christoph.grein
2008-06-11 12:56   ` Markus Schoepflin
2008-06-11 13:08     ` christoph.grein
2008-06-11 13:28     ` Samuel Tardieu
2008-06-11 13:48       ` Markus Schoepflin
2008-06-11 13:56         ` Samuel Tardieu
2008-06-11 14:58       ` Adam Beneschan
2008-06-11 15:23         ` Markus Schoepflin
2008-06-12  2:37           ` Randy Brukardt
2008-06-12  2:37           ` Randy Brukardt
2008-06-11 15:56         ` Samuel Tardieu
2008-06-11 19:10           ` Adam Beneschan
2008-06-11 19:59             ` Niklas Holsti
2008-06-12  1:16               ` tmoran
2008-06-12  8:27                 ` christoph.grein
2008-06-12  8:45               ` Markus Schoepflin
2008-06-12 16:43                 ` Mike Silva
2008-06-12 18:41                   ` Markus Schöpflin
2008-06-12 20:10                     ` Mike Silva
2008-06-12 20:52                       ` Simon Wright
2008-06-12 23:36                         ` Mike Silva
2008-06-13  5:49                           ` Simon Wright
2008-06-13  7:21                       ` Keith Thompson
2008-06-13 13:31                         ` Mike Silva
2008-06-13 14:45                           ` Markus Schoepflin
2008-06-13 17:52                           ` Keith Thompson
2008-06-13  9:14                       ` Jean-Pierre Rosen
2008-06-12 19:05 ` richtmyer [this message]
2008-06-12 21:26   ` Samuel Tardieu
2008-06-12 22:42     ` Adam Beneschan
2008-06-13  7:11       ` Samuel Tardieu
2008-06-13  8:27       ` christoph.grein
2008-06-13 16:21         ` Adam Beneschan
2008-06-15 19:33           ` Robert A Duff
2008-06-16 14:50             ` Adam Beneschan
2008-06-16 19:18               ` Robert A Duff
2008-06-17  6:03               ` christoph.grein
2008-06-17  7:22                 ` christoph.grein
2008-06-13  8:24     ` Peter Hermann
2008-06-13 14:47       ` Samuel Tardieu
2008-06-14 11:48         ` John B. Matthews
replies disabled

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