comp.lang.ada
 help / color / mirror / Atom feed
From: Shark8 <onewingedshark@gmail.com>
Subject: Re: 'Size of an object
Date: Tue, 11 Sep 2012 10:07:05 -0700 (PDT)
Date: 2012-09-11T10:07:05-07:00	[thread overview]
Message-ID: <f3f4cf68-a269-458d-bb1b-4f7bb1e8cc04@googlegroups.com> (raw)
In-Reply-To: <97ff13ad-308a-416f-a300-6c7d9da3d71b@googlegroups.com>

On Tuesday, September 11, 2012 9:52:03 AM UTC-6, Adam Beneschan wrote:
> I had a customer ask a simple question and found that I didn't really
> know the answer, and I'm not even sure where there is a clear answer.
> 
> The question has to do with X'Size where X is an object.  RM 13.3(40)
> says this "denotes the size in bits of the representation of the
> object".  Maybe I'm being dense, but this doesn't seem to clarify
> things.
> 
> Suppose you have an enumeration type with eight literals, and no other
> representation or aspect clauses apply to the type:
>    type Enum is (E0, E1, E2, E3, E4, E5, E6, E7);
> I think Enum'Size should be 3 in most or all implementations.  Now suppose
> you have a local variable of that type:
> 
>    procedure Proc is
>       E : Enum;
>    begin
>       Put_Line (Integer'Image (E'Size));
>    end Proc;
> 
> What would you expect E'Size to be, and why?  In a larger procedure,
> what might you use 'Size on a local variable for; if you wouldn't ever
> use it on a local variable, then what kinds of *objects* (not types or
> subtypes) might you apply 'Size to, and what would you do with the value?

Well, 8, if it's on an x86 machine.
There's no Pragma Pack, or Optimize(Space) so that means that the machine's byte-size or word-size would make sensible choices for the compiler: the packing/unpacking could be too expensive WRT memory/processing-time if that were the default for everything [every access to every variable having to be packed/unpacked - calculated on - repacked and stored].



  parent reply	other threads:[~2012-09-11 17:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-11 15:52 'Size of an object Adam Beneschan
2012-09-11 16:20 ` Micronian Coder
2012-09-11 16:21 ` Vasiliy Molostov
2012-09-11 16:27 ` Dmitry A. Kazakov
2012-09-11 16:28 ` björn lundin
2012-09-11 17:07 ` Shark8 [this message]
2012-09-11 18:11 ` AdaMagica
2012-09-11 22:21   ` Adam Beneschan
replies disabled

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