Pointer semantics in CTFE

Artur Skawina art.08.09 at gmail.com
Sun May 27 06:02:36 PDT 2012


On 05/27/12 02:45, Walter Bright wrote:
> 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
>> http://www.cplusplus.com/reference/clibrary/cstring/memcpy/
>> 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.
> 

Note that if pointer comparison is allowed, subtraction should too.
Ie if 'p1>=p2' works, then it is reasonable to expect 'p1-p2<=i' to
also work.

artur


More information about the Digitalmars-d mailing list