comp.lang.ada
 help / color / mirror / Atom feed
From: "Marc A. Criley" <marccriley@earthlink.net>
Subject: The Incredible Shrinking Type
Date: 2000/11/06
Date: 2000-11-06T00:00:00+00:00	[thread overview]
Message-ID: <3A0703F5.9333AE56@earthlink.net> (raw)

The following program exhibits what is, to me, somewhat unexpected behavior.  I
define an overly long type by applying a size attibute of 72 bits.  The Linux
GNAT compiler (3.13) allocates 128 bits for objects of this type, which is a
reasonable thing for it to do.

However, when passing an instance of this type as a parameter to a procedure and
extracting its 'Size, the result is 64.  What happened to the rest of the bits? 
Granted, they were unused, but still...  Where is this behavior addressed by the
language (if it is), or is it a freedom granted to compiler implementor's?

--------------------------------------------------------------
with System;
with Text_IO; use Text_IO;

procedure Chk_Size is

   type Modest_Type is range 0..99;
   for Modest_Type'Size use 72;

   MT : Modest_Type;

   procedure Dump_Size(Param : Modest_Type) is
   begin
      Put_Line("Param'Size is" & Natural'Image(Param'Size));
   end Dump_Size;

begin
   Put_Line("Modest_Type size: " & Natural'Image(Modest_Type'Size));
   Put_Line("MT obj size:      " & Natural'Image(MT'Size));

   Dump_Size(MT);

end Chk_Size;
--------------------------------------------------------------

Compiling this does generate the warning:

chk_size.adb:7:29: warning: 64 bits of "Modest_Type" unused

Running it produces:

Modest_Type size:  72
MT obj size:       128
Param'Size is 64


Marc A. Criley




             reply	other threads:[~2000-11-06  0:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-11-06  0:00 Marc A. Criley [this message]
2000-11-07  0:04 ` The Incredible Shrinking Type Robert Dewar
2000-11-07  0:00   ` Nicolas Brunot
2000-11-07  0:00     ` Robert Dewar
2000-11-08  0:00       ` Nicolas Brunot
2000-11-09  5:41         ` Robert Dewar
2000-11-07  0:00   ` Marc A. Criley
2000-11-07  0:00     ` Robert Dewar
replies disabled

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