[Issue 24377] Error: negative array dimension `3145728u * 1024u`[32bit]
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Feb 11 23:31:43 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24377
--- Comment #5 from Iain Buclaw <ibuclaw at gdcproject.org> ---
(In reply to kdevel from comment #4)
> (In reply to Iain Buclaw from comment #3)
> > You're allocating an array that takes up more than half the address space,
> > so that is already pretty dubious.
> Up to about 3.5 GiB the allocation is legit in 32 bit mode. But even with a
> 2 GiB allocation the error shows up:
>
> $ cat nad2g.d
> import std.stdio;
>
> void main()
> {
> auto arr = new char [2u * 1024 * 1024 * 1024]; // <--- error
> writefln ("%X", arr.length);
> }
> $ dmd -m32 nad2g.d
> nad2g.d(5): Error: negative array dimension `2097152u * 1024u`
It is based on the error for static arrays.
```
Error: `char[cast(size_t)2147483648]` size 1 * 2147483648 exceeds 0x7fffffff
size limit for static array
```
The hard limit is the max supported static data size for the target.
GCC will even warn about doing such things (i.e: malloc/calloc).
```
warning: argument 1 value ‘2147483648’ exceeds maximum object size 2147483647
```
--
More information about the Digitalmars-d-bugs
mailing list