why is the behavior of pointers to 0 width doing this?
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Fri Jul 4 08:17:34 UTC 2025
```d
import std.stdio;
__gshared int literal;
void main() {
int[0] callstack;
(&callstack+literal).writeln;
}
```
```asm
_Dmain:
.Lfunc_begin0:
.file 1 "/" "app/example.d"
.loc 1 5 0
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset %rbp, -16
movq %rsp, %rbp
.cfi_def_cfa_register %rbp
subq $16, %rsp
movq _D7example7literali at GOTPCREL(%rip), %rax
movslq (%rax), %rax
leaq -4(%rbp), %rdi
imulq $0, %rax, %rax
addq %rax, %rdi
.Ltmp0:
.loc 1 7 5 prologue_end
callq _D3std5stdio__T7writelnTPG0iZQoFNfQkZv at PLT
.loc 1 8 1
xorl %eax, %eax
.loc 1 8 1 epilogue_begin is_stmt 0
addq $16, %rsp
popq %rbp
.cfi_def_cfa %rsp, 8
retq
```
Its the famed equation ``ax+b``.
But with ``a * x`` becoming ``0`` by the frontend.
More information about the Digitalmars-d-learn
mailing list