digitalmars.D - Dynamic array length ABI unit
- =?UTF-8?B?Ikx1w61z?= Marques" (9/9) Jun 16 2014 Regarding the D ABI, http://dlang.org/abi.html , I've noticed
- Daniel Murphy (4/12) Jun 16 2014 It _is_ in T units. It is exactly the dimension of the array, not the s...
- =?UTF-8?B?Ikx1w61z?= Marques" (14/20) Jun 16 2014 Ah, OK. I was mislead by the following:
- David Nadlinger (4/8) Jun 16 2014 Ah, that clears up the confusion. Array casts are "smart" and
- David Nadlinger (7/16) Jun 16 2014 "Dimension" seems to say "number of elements" to me without much
- =?UTF-8?B?Ikx1w61z?= Marques" (4/8) Jun 16 2014 I think you are right, my comment made more sense if it was the
Regarding the D ABI, http://dlang.org/abi.html , I've noticed that the description for dynamic arrays seems ambiguous: offset property contents 0 .length array dimension size_t .ptr pointer to array data Couldn't "array dimension" be either in bytes or in T units, for a T[]? It seems to be in bytes (I had assumed it was in T units). If you agree that it is ambiguous, please tweak the description to be more precise.
Jun 16 2014
""Luís Marques " wrote in message news:fykakpufqivskbnusxgl forum.dlang.org...Regarding the D ABI, http://dlang.org/abi.html , I've noticed that the description for dynamic arrays seems ambiguous: offset property contents 0 .length array dimension size_t .ptr pointer to array data Couldn't "array dimension" be either in bytes or in T units, for a T[]? It seems to be in bytes (I had assumed it was in T units). If you agree that it is ambiguous, please tweak the description to be more precise.It _is_ in T units. It is exactly the dimension of the array, not the size in memory.
Jun 16 2014
On Monday, 16 June 2014 at 11:54:27 UTC, Daniel Murphy wrote:Ah, OK. I was mislead by the following: 1: int[] a1 = [42]; 2: ubyte[] a2 = cast(ubyte[]) a1; 3: writeln(a2); I thought line 2 did a reinterpret_cast on the a1 array header (length + ptr), so I expected a2 == [42], but it is equal to [42, 0, 0, 0] (casts the array contents, adjusts the array length). Forcing a reinterpret_cast-style cast shows that indeed length is in T units, as I originally expected: int[] a1 = [42]; void* p = &a1; ubyte[] a2 = *cast(ubyte[]*) p; assert(a2 == [42]);Couldn't "array dimension" be either in bytes or in T units, for a T[]? It seems to be in bytes (I had assumed it was in T units). If you agree that it is ambiguous, please tweak the description to be more precise.It _is_ in T units. It is exactly the dimension of the array, not the size in memory.
Jun 16 2014
On Monday, 16 June 2014 at 13:11:24 UTC, Luís Marques wrote:Ah, OK. I was mislead by the following: 1: int[] a1 = [42]; 2: ubyte[] a2 = cast(ubyte[]) a1; 3: writeln(a2);Ah, that clears up the confusion. Array casts are "smart" and automatically divide down the length as needed, or fail otherwise. David
Jun 16 2014
On Monday, 16 June 2014 at 11:44:53 UTC, Luís Marques wrote:Regarding the D ABI, http://dlang.org/abi.html , I've noticed that the description for dynamic arrays seems ambiguous: offset property contents 0 .length array dimension size_t .ptr pointer to array data Couldn't "array dimension" be either in bytes or in T units, for a T[]? It seems to be in bytes (I had assumed it was in T units). If you agree that it is ambiguous, please tweak the description to be more precise."Dimension" seems to say "number of elements" to me without much room for interpretation (which it indeed is). Feel free to open a pull request if you have an idea for a better description, though. Best, David
Jun 16 2014
On Monday, 16 June 2014 at 12:27:03 UTC, David Nadlinger wrote:"Dimension" seems to say "number of elements" to me without much room for interpretation (which it indeed is). Feel free to open a pull request if you have an idea for a better description, though.I think you are right, my comment made more sense if it was the other way (number of bytes). My bad, sorry for decreasing the S/N ratio of the forum :P
Jun 16 2014