* Re: aliased & packed?
@ 1997-05-11 0:00 tmoran
1997-05-11 0:00 ` Robert Dewar
0 siblings, 1 reply; 13+ messages in thread
From: tmoran @ 1997-05-11 0:00 UTC (permalink / raw)
>take the access of a packed array, but then the *array* needs to be
>aliased, not its components. The components only need to be aliased
>if you need the access of individual array elements, but clearly that
>makes no sense if the elements are on arbitrary bit boundaries.
Given
type Image_type is array(0 .. last_row, 0 .. last_col) of aliased BW_Bit_type;
pragma Pack(Image_Type);
If you want to pass, say, the right half of the fifth scan line,
The_Image(4, 320 .. 639), which is done in Windows by passing
the address of The_Image(4,320). (320 being divisible by 8)
Or look at ARM B.3(23), where char_array is defined as a packed array
of aliased 'char'. Is this different except in the empirical sense
that on most machines a char is addressable and a bit is not?
Having been bitten in the past by passing an array to an external
function, and finding the external function looking at a descriptor
when it thought it was looking at the first data element, my coding
style has evolved to pass the address of the first data element
instead. Is this no longer necessary with any correct Ada 95 compiler?
It was suggested that 'address be used instead of 'access. Do the
rules of Ada say that should always work, on any compiler, for an
Imported function? Clearly 'address and 'access are not normally
assumed identical (or there would be no point to
System.Address_To_Access_Conversions).
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: aliased & packed?
1997-05-11 0:00 aliased & packed? tmoran
@ 1997-05-11 0:00 ` Robert Dewar
1997-05-11 0:00 ` Tom Moran
0 siblings, 1 reply; 13+ messages in thread
From: Robert Dewar @ 1997-05-11 0:00 UTC (permalink / raw)
Tom Moran said
<< It was suggested that 'address be used instead of 'access. Do the
rules of Ada say that should always work, on any compiler, for an
Imported function? Clearly 'address and 'access are not normally
assumed identical (or there would be no point to
System.Address_To_Access_Conversions).>>
Well, address is very precisely defined in terms of storage units
occupied, so its meaning, though target dependent of course, should
certainly be compiler independent assuming the same data layouts.
Note this assumption, there is nothing in Ada that specifies the
mapping of array elements, so any time you make an assumption about
this, you are writing implementation dependent code.
In the case of packed arrays, since none of the languages you are
interfacing to support packed arrays, pragma Convention does not
help to guarantee the order.
Obviously you definitely CANNOT expect access to work on a packed array.
This in fact is a good example of why access values and pointers are
totally different. In writing 'access of a packed aliased array element
and expecting it to work, you are making the typical mistake of thinking
of the 'access as being a pointer, and assuming that the pointer is
implemented as an address.
It is quite clear that 'Address is *far* more appropriate in any case
for the use you have in mind, and is exactly at the right level of
abstraction.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: aliased & packed?
1997-05-11 0:00 ` Robert Dewar
@ 1997-05-11 0:00 ` Tom Moran
1997-05-12 0:00 ` Robert Dewar
0 siblings, 1 reply; 13+ messages in thread
From: Tom Moran @ 1997-05-11 0:00 UTC (permalink / raw)
> Well, address is very precisely defined in terms of storage units
> occupied, so its meaning, though target dependent of course, should
> certainly be compiler independent assuming the same data layouts.
Which still does not answer my question of whether I can assume
that 'address will generate the right thing for an Imported C function,
especially when I see that many such C functions are defined in various
examples I see as taking 'access rather than 'address parameters.
> Obviously you definitely CANNOT expect access to work on a packed array.
Does that mean I can't expect Interfaces.C
type char_array is array(size_t range <>) of aliased char;
pragma Pack(char array);
to work?
Also, how about the question of 'address or 'access of the array itself
rather than a component (eg the first element). Is either or both of
'address or 'access, in Ada 95, supposed to give an Imported function
the address of the first data element, rather than the address of a
descriptor?
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: aliased & packed?
1997-05-11 0:00 ` Tom Moran
@ 1997-05-12 0:00 ` Robert Dewar
1997-05-12 0:00 ` Robert A Duff
0 siblings, 1 reply; 13+ messages in thread
From: Robert Dewar @ 1997-05-12 0:00 UTC (permalink / raw)
Tom Moran says
<<type char_array is array(size_t range <>) of aliased char;
pragma Pack(char array);
to work?>>
Of course it will work. But what do you mean by working? There is no
requirement in this case that the pragma Pack have any effect. Indeed
on most byte addressable machines, the pragma Pack will have no effect
anyway.
with GNAT, pragma Pack never has any effect if the components are aliased,
and indeed you will get a warning that the pragma Pack is ignored.
However, it is not silly to put it in necessarily, since you can imagine
a machine that allows independent addressability of characters, but
still has a cost associated with 8-bit packing of characters. The old
alpha comes close to being like that, but actually on the Alpha, we decide
to pack this by default anyway.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: aliased & packed?
1997-05-12 0:00 ` Robert Dewar
@ 1997-05-12 0:00 ` Robert A Duff
[not found] ` <1997May13.065907.1@eisner>
0 siblings, 1 reply; 13+ messages in thread
From: Robert A Duff @ 1997-05-12 0:00 UTC (permalink / raw)
In article <dewar.863449539@merv>, Robert Dewar <dewar@merv.cs.nyu.edu> wrote:
>However, it is not silly to put it in necessarily, since you can imagine
>a machine that allows independent addressability of characters, but
>still has a cost associated with 8-bit packing of characters. The old
>alpha comes close to being like that, but actually on the Alpha, we decide
>to pack this by default anyway.
I'm curious: How much is the cost, on the alpha, of accessing the array
by 8-bit bytes? And which models of Alpha are we talking about, and
when did they come out? I only have the very early description of the
alpha architecture, so I have no idea what's the difference between the
21x64, for various x.
- Bob
^ permalink raw reply [flat|nested] 13+ messages in thread
* aliased & packed?
@ 1997-05-09 0:00 Tom Moran
1997-05-09 0:00 ` Stephen Leake
1997-05-10 0:00 ` Robert Dewar
0 siblings, 2 replies; 13+ messages in thread
From: Tom Moran @ 1997-05-09 0:00 UTC (permalink / raw)
Clearly you can't do it. I'd like to use pragma Pack for bits in a
black/white bitmap array. That's easy to manipulate. But to actually
display it I need to do a system call and pass the address. If it
wasn't packed, Image'unchecked_access would be appropriate. But
that won't work because Image would have to be aliased, and it can't
be because it's packed. Must I drop 'Pack' and make it an array of
bytes and do my own masking, shifting, etc? What's the cleanest/most
portable/best way to accomplish the task?
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: aliased & packed?
1997-05-09 0:00 Tom Moran
@ 1997-05-09 0:00 ` Stephen Leake
1997-05-09 0:00 ` Tom Moran
1997-05-10 0:00 ` Robert Dewar
1 sibling, 1 reply; 13+ messages in thread
From: Stephen Leake @ 1997-05-09 0:00 UTC (permalink / raw)
Tom Moran wrote:
>
> Clearly you can't do it. I'd like to use pragma Pack for bits in a
> black/white bitmap array. That's easy to manipulate. But to actually
> display it I need to do a system call and pass the address. If it
> wasn't packed, Image'unchecked_access would be appropriate. But
> that won't work because Image would have to be aliased, and it can't
> be because it's packed. Must I drop 'Pack' and make it an array of
> bytes and do my own masking, shifting, etc? What's the cleanest/most
> portable/best way to accomplish the task?
Since the system call wants the address, use 'address (converted to
Long_Integer or whatever is required). You have to do some conversion to
pass to a system call; converting from 'unchecked_access is no "cleaner"
than converting from 'address.
As for portability, there will be a different system call to display
bitmaps, so you'll have to change a lot more than the attribute!
--
- Stephe
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: aliased & packed?
1997-05-09 0:00 Tom Moran
1997-05-09 0:00 ` Stephen Leake
@ 1997-05-10 0:00 ` Robert Dewar
1 sibling, 0 replies; 13+ messages in thread
From: Robert Dewar @ 1997-05-10 0:00 UTC (permalink / raw)
Tom Moran said
<<Clearly you can't do it. I'd like to use pragma Pack for bits in a
black/white bitmap array. That's easy to manipulate. But to actually
display it I need to do a system call and pass the address. If it
wasn't packed, Image'unchecked_access would be appropriate. But
that won't work because Image would have to be aliased, and it can't
be because it's packed. Must I drop 'Pack' and make it an array of
bytes and do my own masking, shifting, etc? What's the cleanest/most
portable/best way to accomplish the task?>>
I don't understand, what is Image? The whole array? Of course you can
take the access of a packed array, but then the *array* needs to be
aliased, not its components. The components only need to be aliased
if you need the access of individual array elements, but clearly that
makes no sense if the elements are on arbitrary bit boundaries.
If what you want to do makes sense here, it can be done, please explain
more clearly what you are trying to do precisely!
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~1997-05-14 0:00 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-05-11 0:00 aliased & packed? tmoran
1997-05-11 0:00 ` Robert Dewar
1997-05-11 0:00 ` Tom Moran
1997-05-12 0:00 ` Robert Dewar
1997-05-12 0:00 ` Robert A Duff
[not found] ` <1997May13.065907.1@eisner>
1997-05-13 0:00 ` Robert A Duff
1997-05-13 0:00 ` Larry Kilgallen
1997-05-14 0:00 ` Richard Kenner
1997-05-13 0:00 ` Robert Dewar
-- strict thread matches above, loose matches on Subject: below --
1997-05-09 0:00 Tom Moran
1997-05-09 0:00 ` Stephen Leake
1997-05-09 0:00 ` Tom Moran
1997-05-10 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