Segfault when writing to module-scope dynamic array
rombankzero
bogomancer at gmail.com
Mon Nov 18 13:22:20 UTC 2019
On Monday, 18 November 2019 at 12:42:26 UTC, Adam D. Ruppe wrote:
> My guess is the compiler is seeing a static string and
> incorrectly putting it in the read-only segment with the other
> strings, and then writing to it thus triggers that segfault.
Yeah, that appears to be what's happening. For the record, I
tried it on both Linux and Windows, and only got a segfault on
Linux. And the fact that the ubyte[] case works only added to the
confusion.
On Monday, 18 November 2019 at 12:42:26 UTC, Adam D. Ruppe wrote:
> but yeah this is NOT what it does. It runs new at *compile
> time* which means that `array` variable is pointing to static
> memory, it is not heap allocated at all.
Are there cases where this behavior is useful? Because it seems
pretty surprising to me. Like, when I see the "new" keyword, I
immediately think "heap allocation", not anything being put into
the data segment.
More information about the Digitalmars-d-learn
mailing list