comp.lang.ada
 help / color / mirror / Atom feed
* Type size vs. actual size difference.
@ 2000-03-20  0:00 Bruce Detter
  2000-03-20  0:00 ` Stanley R. Allen
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Bruce Detter @ 2000-03-20  0:00 UTC (permalink / raw)


Using GNAT 3.12 on Win NT 4.0.  We have defined a record that has a length
of 214 bytes.  The type'Size attribute reports 214, but when we declare a
variable of the record type (X : Type) the size attribute X'Size reports
216.  It appears the actual variable size takes into account adjustments to
word boundaries (and of course the type'Size attribute can't do this).  Is
there a preprocessor command or pragma command that will force byte boundary
alignment so that the type size agrees with the actual size?

Thanks...
--
Bruce C. Detter III






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

* Re: Type size vs. actual size difference.
  2000-03-20  0:00 Type size vs. actual size difference Bruce Detter
  2000-03-20  0:00 ` Stanley R. Allen
  2000-03-20  0:00 ` tmoran
@ 2000-03-20  0:00 ` Vladimir Olensky
  2000-03-20  0:00   ` Robert Dewar
  2 siblings, 1 reply; 6+ messages in thread
From: Vladimir Olensky @ 2000-03-20  0:00 UTC (permalink / raw)



Bruce Detter wrote in message <8b5hhp$pvv1@svlss.lmms.lmco.com>...
>Using GNAT 3.12 on Win NT 4.0.  We have defined a record that has a length
>of 214 bytes.  The type'Size attribute reports 214, but when we declare a
>variable of the record type (X : Type) the size attribute X'Size reports
>216.  It appears the actual variable size takes into account adjustments to
>word boundaries (and of course the type'Size attribute can't do this).  Is
>there a preprocessor command or pragma command that will force byte
boundary
>alignment so that the type size agrees with the actual size?


This topic was discussed recently here.
Topic name was:  Size (novice question).

Shortly - size of the stand-alone variable is a multiple of storage units.
(Variable should be stored and accessed in memory in effective manner ).

In your case 216 = Byte'Size*7;
But Type'Size is exactly 214.

If your record would be a part of the other record  it's
size could be made exactly 214 bits.

Regards,
Vladimir_Olensky






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

* Re: Type size vs. actual size difference.
  2000-03-20  0:00 ` Vladimir Olensky
@ 2000-03-20  0:00   ` Robert Dewar
  2000-03-20  0:00     ` Vladimir Olensky
  0 siblings, 1 reply; 6+ messages in thread
From: Robert Dewar @ 2000-03-20  0:00 UTC (permalink / raw)


In article <sdcm3eaplul93@corp.supernews.com>,
  "Vladimir Olensky" <vladimir_olensky@yahoo.com> wrote:
> Topic name was:  Size (novice question).

(not relevant stuff snipped)

Vladimir, you translated 214 bytes into 214 bits in your
reading, and thus answered a completely different question!

Many are puzzled by this discrepancy between type'size and
object'size, even though it is perfectly in accordance with
the RM (and indeed is expected behavior). We find that quite
a bit of our support effort involves helping people deal with
these kinds of problems (the first step is to find out what
the underlying intention is).

Robert Dewar
Ada Core Technologies


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: Type size vs. actual size difference.
  2000-03-20  0:00 Type size vs. actual size difference Bruce Detter
  2000-03-20  0:00 ` Stanley R. Allen
@ 2000-03-20  0:00 ` tmoran
  2000-03-20  0:00 ` Vladimir Olensky
  2 siblings, 0 replies; 6+ messages in thread
From: tmoran @ 2000-03-20  0:00 UTC (permalink / raw)


>We have defined a record that has a length of 214 bytes.
  So you have
type sometype is record ...
for sometype'size use 214*8;
x : sometype;
begin
ada.text_io.put_line(integer'image(x'size/8));
  and it prints 216?




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

* Re: Type size vs. actual size difference.
  2000-03-20  0:00 Type size vs. actual size difference Bruce Detter
@ 2000-03-20  0:00 ` Stanley R. Allen
  2000-03-20  0:00 ` tmoran
  2000-03-20  0:00 ` Vladimir Olensky
  2 siblings, 0 replies; 6+ messages in thread
From: Stanley R. Allen @ 2000-03-20  0:00 UTC (permalink / raw)


Bruce Detter wrote:
> 
> Using GNAT 3.12 on Win NT 4.0.  We have defined a record that has a length
> of 214 bytes.  The type'Size attribute reports 214, but when we declare a
> variable of the record type (X : Type) the size attribute X'Size reports
> 216.  It appears the actual variable size takes into account adjustments to
> word boundaries (and of course the type'Size attribute can't do this).  Is
> there a preprocessor command or pragma command that will force byte boundary
> alignment so that the type size agrees with the actual size?
> 

I don't think there is a standard way to do this.  On GNAT, there
is an attribute T'Object_Size, which when applied to types will yield
the number of bits that would be used for a variable if declared
"A : T;".  On the old DEC Ada compiler, you could use the attribute
T'Machine_Size, which would do the same thing.  I don't know about
other compilers.

It would be nice if something like T'Object_Size was standard.  In some
cases it's necessary for me to declare a 'dummy' variable of a type
to get this.

-- 
Stanley Allen
mailto:Stanley_R_Allen@raytheon.com




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

* Re: Type size vs. actual size difference.
  2000-03-20  0:00   ` Robert Dewar
@ 2000-03-20  0:00     ` Vladimir Olensky
  0 siblings, 0 replies; 6+ messages in thread
From: Vladimir Olensky @ 2000-03-20  0:00 UTC (permalink / raw)



Robert Dewar wrote in message <8b5n8c$kkl$1@nnrp1.deja.com>...
>In article <sdcm3eaplul93@corp.supernews.com>,
>  "Vladimir Olensky" <vladimir_olensky@yahoo.com> wrote:
>> Topic name was:  Size (novice question).
>
>(not relevant stuff snipped)
>
>Vladimir, you translated 214 bytes into 214 bits in your
>reading, and thus answered a completely different question!


Oops, I see .

Probably I was a little bit tired and a wrong trigger switched
on in my mind :-)

Thanks,
Vladimir Olensky







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

end of thread, other threads:[~2000-03-20  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-20  0:00 Type size vs. actual size difference Bruce Detter
2000-03-20  0:00 ` Stanley R. Allen
2000-03-20  0:00 ` tmoran
2000-03-20  0:00 ` Vladimir Olensky
2000-03-20  0:00   ` Robert Dewar
2000-03-20  0:00     ` Vladimir Olensky

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