Thread overview
why is the behavior of pointers to 0 width doing this?
Jul 04
monkyyy
Jul 04
monkyyy
July 04
import std;
unittest{
	int[0] callstack;
	(&callstack).writeln;
	(&callstack+1000).writeln;
}

this prints the same value twice, I assume its some kind of void replacement, then an optimizer, then related to whatever os memory magic does some math.

July 04
```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@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@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.
July 04
On Friday, 4 July 2025 at 08:17:34 UTC, Richard (Rikki) Andrew Cattermole wrote:
> ```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@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@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.

```d
import std;
unittest{
	void* callstack;
	(callstack).writeln;
	(callstack+1000).writeln;
}
```
Im confused why 0 stride pointers behave differently then void*; shouldnt they be vaguely similar?