CTFE and minimizing the GC
ketmar via Digitalmars-d
digitalmars-d at puremagic.com
Mon Oct 31 17:34:26 PDT 2016
On Monday, 31 October 2016 at 20:23:13 UTC, Jacob Carlborg wrote:
> Using StackFront at CTFE will give you the following error:
>
> region.d(323,20): Error: null - null cannot be interpreted at
> compile time: cannot subtract pointers to two different memory
> blocks
i don't remember what specs says about this situation, tbh, but
this is UB in C, for example. it doesn't matter that any sane
person is ignoring it and assuming that subtracting from a
pointer that points one cell after the region is valid, it is
still technically unsafe operation (and possible UB).
this can be solved in two ways:
1. introducing a hack in CTFE engine, so it will explicitly allow
using such "end-start" pointer math if result is still in the
region at which "start" points (i'd prefer this solution)
2. fix allocators, so instead of having "_end" points past the
allocated block, it will point right at the last cell, and do
"+1" in each calculation (highly error-prone, as almost nobody is
using end pointers in this way, so there will be forgotten
increments).
allocators will break later, of course, but at least this issue
should be fixed in CTFE engine, i think.
More information about the Digitalmars-d
mailing list