comp.lang.ada
 help / color / mirror / Atom feed
* Packed array size question....
@ 1997-03-07  0:00 Marc Bejerano
  1997-03-07  0:00 ` Robert Dewar
  0 siblings, 1 reply; 8+ messages in thread
From: Marc Bejerano @ 1997-03-07  0:00 UTC (permalink / raw)



type foo is array (1..512) of character

foo'size reports it to be 4096 bytes in length.

I tried:

	pragma pack (foo)

I tried:

	for foo'size use 512;

none of them work! help! I am going out of my mind trying to figure this
out.


Thanks in advance,


Marc




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

* Re: Packed array size question....
  1997-03-07  0:00 Packed array size question Marc Bejerano
@ 1997-03-07  0:00 ` Robert Dewar
  1997-03-13  0:00   ` Matthew Heaney
  0 siblings, 1 reply; 8+ messages in thread
From: Robert Dewar @ 1997-03-07  0:00 UTC (permalink / raw)



Marc says

<<type foo is array (1..512) of character

foo'size reports it to be 4096 bytes in length.

I tried:

        pragma pack (foo)

I tried:

        for foo'size use 512;

none of them work! help! I am going out of my mind trying to figure this
out.


Thanks in advance,


Marc>>


A good idea in such a case is to check your assumptions. You are assuming
that Size yields the size in storage units, but let's read the RM:

40  X'Size
                Denotes the size in bits of the representation of the object.
                The value of this attribute is of the type universal_integer.


Ah ha! bits!!!
:-)





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

* Re: Packed array size question....
  1997-03-07  0:00 ` Robert Dewar
@ 1997-03-13  0:00   ` Matthew Heaney
       [not found]     ` <01bc300c$247f6200$0e096dce@my-pc.neosoft.com>
  0 siblings, 1 reply; 8+ messages in thread
From: Matthew Heaney @ 1997-03-13  0:00 UTC (permalink / raw)



In article <dewar.857784634@merv>, dewar@merv.cs.nyu.edu (Robert Dewar) wrote:

>Marc says

>none of them work! help! I am going out of my mind trying to figure this
>out.
>

>A good idea in such a case is to check your assumptions. You are assuming
>that Size yields the size in storage units, but let's read the RM:
>
>40  X'Size
>                Denotes the size in bits of the representation of the object.
>                The value of this attribute is of the type universal_integer.
>
>
>Ah ha! bits!!!
>:-)

Forgetting that 'Size returns size in bits is an error that Ada programmers
often make.

You have to admit that the attribute

X'Size_In_Storage_Elements 

would make a lot of sense.  In practice, knowing the number of storage
elements occupied by an object is much more useful than knowing the number
of bits.

Surprisingly, this attribute was not included in Ada 95!

Matt

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




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

* Re: Packed array size question....
       [not found]     ` <01bc300c$247f6200$0e096dce@my-pc.neosoft.com>
@ 1997-03-15  0:00       ` Robert Dewar
  1997-03-16  0:00       ` Matthew Heaney
  1 sibling, 0 replies; 8+ messages in thread
From: Robert Dewar @ 1997-03-15  0:00 UTC (permalink / raw)



Regarding Size_In_Storage_Elements ...

as is clear from the RM quote, this is the size that will be requested
from the storage allocator, and may include control words, padding,
alignment bytes etc. It may NOT correspond to the stored size of the
object in memory. In particular, if you use 'Address and assume that
it points to a block of this length that contains data, you may be
surprised, there is no guarantee that this would work, and in general
it will not!





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

* Re: Packed array size question....
       [not found]     ` <01bc300c$247f6200$0e096dce@my-pc.neosoft.com>
  1997-03-15  0:00       ` Robert Dewar
@ 1997-03-16  0:00       ` Matthew Heaney
  1997-03-16  0:00         ` Robert Dewar
  1 sibling, 1 reply; 8+ messages in thread
From: Matthew Heaney @ 1997-03-16  0:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1403 bytes --]


In article <01bc300c$247f6200$0e096dce@my-pc.neosoft.com>, "Pat Rogers"
<progers@acm.org> wrote:

>> You have to admit that the attribute
>> 
>> X'Size_In_Storage_Elements 
>> 
>> would make a lot of sense.  In practice, knowing the number of storage
>> elements occupied by an object is much more useful than knowing the
>number
>> of bits.
>> 
>> Surprisingly, this attribute was not included in Ada 95!
>
>From the RM:
>
>145     S�Max_Size_In_Storage_Elements
>        For every subtype S:
>
>146     Denotes the maximum value for Size_In_Storage_Elements that will be
>requested via Allocate for an
>        access type whose designated subtype is S. The value of this
attribute is
>of type universal_integer. 
>        See 13.11.1.
>
>Close enough?

No, because that attribute only applies to memory allocated via an allocator.  

I wanted an attribute I could apply to stack objects:

declare
   O : T;
begin
   write (addr => O'Address, nbytes => O'Size_In_Storage_Elements);
end;

instead of

declare
   O : T;
begin
   write (addr => O'Address, nbytes => O'Size / 8);
end;

(Of course, T is a first-named subtype whose size is an integral multiple
of System.Storage_Unit.  And in this case, System.Storage_Unit = 8.)

Matt

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




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

* Re: Packed array size question....
  1997-03-16  0:00       ` Matthew Heaney
@ 1997-03-16  0:00         ` Robert Dewar
  1997-03-19  0:00           ` Dale Stanbrough
  0 siblings, 1 reply; 8+ messages in thread
From: Robert Dewar @ 1997-03-16  0:00 UTC (permalink / raw)



Mathew Heaney wrote:

<<declare
   O : T;
begin
   write (addr => O'Address, nbytes => O'Size / 8);
end;>>

Better is O'Size / Storage_Unit -- makes it clearer what is going on, and
indeed to be absolutely right, you should write

(O'Size + (Storage_Unit - 1)) / Storage_Unit

which is an annoying mouthful, and i agree that an attribute would be nice.
We considered adding it to GNAT, but it would seem to create confusion,
given the Value_Size vs Object_Size issue.





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

* Re: Packed array size question....
  1997-03-16  0:00         ` Robert Dewar
@ 1997-03-19  0:00           ` Dale Stanbrough
  1997-03-21  0:00             ` Robert Dewar
  0 siblings, 1 reply; 8+ messages in thread
From: Dale Stanbrough @ 1997-03-19  0:00 UTC (permalink / raw)



Robert Dewar writes:

"Better is O'Size / Storage_Unit -- makes it clearer what is going on, and
 indeed to be absolutely right, you should write

 (O'Size + (Storage_Unit - 1)) / Storage_Unit

 which is an annoying mouthful, and i agree that an attribute would be nice.
 We considered adding it to GNAT, but it would seem to create confusion,
 given the Value_Size vs Object_Size issue."


 
	Object'Storage_Unit_Size
	Object'Size_In_Storage_Units
	
?

Dale




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

* Re: Packed array size question....
  1997-03-19  0:00           ` Dale Stanbrough
@ 1997-03-21  0:00             ` Robert Dewar
  0 siblings, 0 replies; 8+ messages in thread
From: Robert Dewar @ 1997-03-21  0:00 UTC (permalink / raw)



Dale said (a bit cryptically)

<<
        Object'Storage_Unit_Size
        Object'Size_In_Storage_Units

?>>

As I say, this is confusing with respect to the 'Value_Size vs 
'Object_Size issue (for a discussion of these two attributes, see the
GNAt documentation).





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

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

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-03-07  0:00 Packed array size question Marc Bejerano
1997-03-07  0:00 ` Robert Dewar
1997-03-13  0:00   ` Matthew Heaney
     [not found]     ` <01bc300c$247f6200$0e096dce@my-pc.neosoft.com>
1997-03-15  0:00       ` Robert Dewar
1997-03-16  0:00       ` Matthew Heaney
1997-03-16  0:00         ` Robert Dewar
1997-03-19  0:00           ` Dale Stanbrough
1997-03-21  0:00             ` Robert Dewar

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