help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Ada array contiguity.
Date: Sun, 19 Feb 2023 16:59:42 +0200	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <tstbm6$doua$>

On 2023-02-19 16:28, J-P. Rosen wrote:
> 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.

I tried to find a rule on "contiguity" in the Ada 2022 RM, but failed. 
Can you point to one? Perhaps this rule is a consequence of C standard 
rules for arrays (pointer arithmetic), and the general idea that Ada 
should allow Convention C for a type only if that type is really 
compatible with the C compiler (in question).

For a constrained array type I would choose to specify the size of the 
component type, and the size of the array type to be the length of the 
array times the component size. That should (also) ensure that the 
elements are stored contiguously (if the Ada compiler accepts this size 

It seems (RM B.3(62.4/3)) that Ada compilers are not required to support 
Convention C for unconstrained array types. RM B.3 (Interfacing with 
C/C++) declares such types with the Pack aspect, but that may or may not 
(AIUI) give a contiguous representation.

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

  reply	other threads:[~2023-02-19 14:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-19 13:34 Ada array contiguity Rod Kay
2023-02-19 14:28 ` J-P. Rosen
2023-02-19 14:59   ` Niklas Holsti [this message]
2023-02-19 15:08     ` Dmitry A. Kazakov
2023-02-19 17:10     ` J-P. Rosen
2023-02-19 17:54       ` Niklas Holsti
2023-02-19 19:05         ` Dmitry A. Kazakov
2023-02-20  7:12         ` J-P. Rosen
2023-02-19 22:02 ` Jeffrey R.Carter
2023-03-01 13:22 ` Rod Kay
replies disabled

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