comp.lang.ada
 help / color / mirror / Atom feed
From: "Vasiliy Molostov" <molostoff@gmail.com>
Subject: Re: 'Size of an object
Date: Tue, 11 Sep 2012 20:21:46 +0400
Date: 2012-09-11T20:21:46+04:00	[thread overview]
Message-ID: <op.wkhbqkg1ka8ora@aspire.local> (raw)
In-Reply-To: 97ff13ad-308a-416f-a300-6c7d9da3d71b@googlegroups.com

Adam Beneschan <adam@irvine.com> писал(а) в своём письме Tue, 11 Sep 2012  
19:52:03 +0400:

> 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.

RM says truth. always. This means you can supply representation clause for  
X and ask lately in code about this representation. If you have not  
supplied representation, it will be almost equal to system unit size  
(8-bit byte or 16-bit word, or else).

> 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:

For intel x86 it would be a 8 or 16, or 32, depending on how memory  
alignment is constrained for this object. You can redefine size to 3 by  
adding representation clause.

>
>    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 this case, it would be a default value of max(system unit size, default  
memory alignment).

> 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?

You can use it in bit string copy ops, in record representation clauses or  
any other, depending on purpose, a similar thing in C is a bit field  
definitions inside 'struct' notation.



  parent reply	other threads:[~2012-09-17  2:48 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 [this message]
2012-09-11 16:27 ` Dmitry A. Kazakov
2012-09-11 16:28 ` björn lundin
2012-09-11 17:07 ` Shark8
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