On 2023-02-19 16:28, J-P. Rosen wrote:
(BTW: try to find a definition of "contiguous". At byte level? At word
level? What if the element does not fill a byte?)
Indeed. But it seems to me that Arr'Size = Arr'Length * Comp'Size is the meaning usually intended for programming purposes.
Hi all,
  I've been told that Ada array elements are not guaranteed to be contiguous unless the 'Convention C' aspect is applied.
  Is this correct ?
Le 19/02/2023 à 14:34, Rod Kay a écrit :
Hi all,
   I've been told that Ada array elements are not guaranteed to be
contiguous unless the 'Convention C' aspect is applied.
   Is this correct ?
The strength of Ada is that it protects you from all implementation
details, thus allowing compilers to choose the most efficient
implementation. Therefore, the answer is yes.
(BTW: try to find a definition of "contiguous". At byte level? At word
level? What if the element does not fill a byte?)
(BTW: try to find a definition of "contiguous". At byte level? At word
level? What if the element does not fill a byte?)
Indeed. But it seems to me that Arr'Size = Arr'Length * Comp'Size is the meaning usually intended for programming purposes.
Le 19/02/2023 à 15:59, Niklas Holsti a écrit :
(BTW: try to find a definition of "contiguous". At byte level? At
word level? What if the element does not fill a byte?)
Indeed. But it seems to me that Arr'Size = Arr'Length * Comp'Size is
the meaning usually intended for programming purposes.
Certainly not if Comp'Size is not an integer number of bytes.
On 2023-02-19 15:59, Niklas Holsti wrote:
On 2023-02-19 16:28, J-P. Rosen wrote:
(BTW: try to find a definition of "contiguous". At byte level?
At word level? What if the element does not fill a byte?)
Indeed. But it seems to me that Arr'Size = Arr'Length * Comp'Size
is the meaning usually intended for programming purposes.
Rather: the bit offset of an element is a linear function of its
position.
On 2023-02-19 17:08, Dmitry A. Kazakov wrote:
Rather: the bit offset of an element is a linear function of its
position.
That is ordering by index, but not contiguity: there may still be gaps between elements. However, I assume you meant that the slope of the
linear function equals the component size, and then it includes contiguity.
The relationship of index order to memory-location order is certainly an aspect that should be considered when interfacing to C or HW.
Pet peeve: on more than one occasion I have been disappointed that Ada representation clauses do not let me specify the index-order of packed
array elements in a word, relative to the bit-numbering order, and I
have had to fall back to using several scalar-type record components, c1
.. c7 say, instead of one array-type component, c(1..7).
  I've been told that Ada array elements are not guaranteed to be contiguous
unless the 'Convention C' aspect is applied.
On 2023-02-19 19:10, J-P. Rosen wrote:
Le 19/02/2023 à 15:59, Niklas Holsti a écrit :
Indeed. But it seems to me that Arr'Size = Arr'Length * Comp'Size is
the meaning usually intended for programming purposes.
Certainly not if Comp'Size is not an integer number of bytes.
I'm not so certain. By choosing various roundings-up of the component
size, you can choose between "bit-contiguous", "byte-contiguous", etc.
For example, bit-contiguous with 2-bit components:
  type Comp is (A, B, C, D) with Size => 2;
  type Arr is array (1 .. 10) of Comp
     with Pack, Size => 10 * Comp'Size;
Nybble-contiguous with Comp'Size => 4, byte- (octet-) contiguous with Comp'Size => 8, etc.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 399 |
Nodes: | 16 (2 / 14) |
Uptime: | 65:17:25 |
Calls: | 8,355 |
Calls today: | 15 |
Files: | 13,159 |
Messages: | 5,893,953 |
Posted today: | 1 |