miscellaneous array questions...

a at a.com a at a.com
Tue Jul 21 03:16:19 UTC 2020


On Monday, 20 July 2020 at 22:05:35 UTC, WhatMeWorry wrote:
> 1) The D Language Reference says:
>
> "There are four kinds of arrays..." with the first example being
> "type*	Pointers to data"  and "int* p;  etc.
>
> At the risk of sounding overly nitpicky, isn't a pointer to an 
> integer simply a pointer to an integer?  How does that pertain 
> to an array?
>
>
> 2) "The total size of a static array cannot exceed 16Mb" What 
> limits this? And with modern systems of 16GB and 32GB, isn't 
> 16Mb excessively small?   (an aside: shouldn't that be 16MB in 
> the reference instead of 16Mb? that is, Doesn't b = bits and B 
> = bytes)
>
>
> 3) Lastly, In the following code snippet, is arrayA and arrayB 
> both allocated on the stack? And how does their scopes and/or 
> lifetimes differ?
>
> ==== module1 =====
> int[100] arrayA;
> void main()
> {
>     int[100] arrayB;
>     // ...
> }
> ==== module1 =====

1) Pointers can be used as arrays with the [] operator, int* p = 
arrayA.ptr; assert(*(p + 99) == p[99]); should access the same 
element.
http://ddili.org/ders/d.en/pointers.html ("Using pointers with 
the array indexing operator []")
2) I've encountered this problem too, it's arbitrary AFAIK but it 
can be circumvented with dynamic arrays.


More information about the Digitalmars-d-learn mailing list