comp.lang.ada
 help / color / mirror / Atom feed
* The Incredible Shrinking Type
@ 2000-11-06  0:00 Marc A. Criley
  2000-11-07  0:04 ` Robert Dewar
  0 siblings, 1 reply; 8+ messages in thread
From: Marc A. Criley @ 2000-11-06  0:00 UTC (permalink / 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




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2000-11-09  5:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-06  0:00 The Incredible Shrinking Type Marc A. Criley
2000-11-07  0:04 ` Robert Dewar
2000-11-07  0:00   ` Marc A. Criley
2000-11-07  0:00     ` 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

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