void my_fatal()
{
*((volatile unsigned int *) 0) = (unsigned int) 0xdeadbeefUL;
}
compile: dmd -O -c test.c
Error: null dereference in function my_fatal
i see in https://github.com/dlang/dmd/blob/b1ac484/src/dmd/backend/cgelem.d#L6253 where the error is emitted, it has a check to allow this with volatile pointers but the keyword is ignored in importC
Comment #1 by bugzilla — 2022-04-20T06:56:43Z
volatile is ignored in ImportC because the D type system has no concept of volatile.
Comment #2 by bugzilla — 2023-04-09T05:50:53Z
You can work around it with something like:
static void* p;
*(unsigned int*)p = (unsigned int) 0xdeadbeefUL;
Comment #3 by robert.schadek — 2024-12-13T19:22:22Z