Pointer semantics in CTFE
newshound2 at digitalmars.com
Sat May 26 17:45:10 PDT 2012
On 5/26/2012 3:59 AM, Don wrote:
> Yes, that's what happens now. But that doesn't help the programmer.
> If it is inside, no problem, the expression is true. But if it is not inside,
> the expression is not false -- it's a compile-time error.
Ok, I understand now what you meant.
> So you can't use it as a test for if it is inside the same object.
> I was confused about how memmove can work in C without relying on undefined
> behaviour. But I just read
> which defines it in terms of an intermediate buffer.
> So maybe, the current CTFE implementation is _exactly_ consistent with the C
> spec. If that's true, though, I find it pretty incredible that there is no way
> to find out if a pointers points a particular array, even if you have pointers
> to both the start and end of that array.
> (OK, I guess you can iterate from start to end, checking for equality, but ..
> bleah .. it's a terrible abstraction inversion).
You could implement it as simply comparing the addresses - you'd be no worse off
than C is, and you would get the correct answer for pointers both in and out of
the array without needing special cases.
More information about the Digitalmars-d