Pointer semantics in CTFE

Don Clugston dac at nospam.com
Wed May 30 03:24:17 PDT 2012


On 30/05/12 01:47, Mehrdad wrote:
> Just a general note: going the "make a special case for two comparisons"
> route won't work if, for example, someone decides to use a lambda for
> comparing pointers.

You mean effectively like:

bool cmp(void *x, void *y)
{
    return x < y:
}

assert ( cmp(x, y) && cmp(x, z) );

?
Yes, this is why it's a special case.


I can imagine how that could be implemented in the current CTFE, I 
cannot see how it could be done reasonably with a JIT CTFE implementation.

You'd have to have a special lamba for "pointer inside a range" rather 
than simple pointer comparisons.

I'm suggesting that "is pointer inside a range" is a different primitive 
operation from "comparison of two pointers to the same memory block".

Even though C code typically uses the latter to implement the former, 
it's relying on undefined behaviour.


More information about the Digitalmars-d mailing list