dmd 1.046 and 2.031 releases

Derek Parnell derek at psych.ward
Mon Jul 6 04:46:05 PDT 2009


On Mon, 06 Jul 2009 03:13:45 -0700, Walter Bright wrote:

> Derek Parnell wrote:
>> On Mon, 06 Jul 2009 00:11:26 -0700, Walter Bright wrote:
>> 
>>> Derek Parnell wrote:
>>>> I'm struggling to see why the compiler cannot just disallow any
>>>> signed<->unsigned implicit conversion? Is it a matter of backward
>>>> compatibility again?
>>> What's the signed-ness of 5?
>> 
>> Positive. A positive number can be assigned to an 'int' if there is no size
>> issue.
> 
> It can also be an unsigned.

Which is a positive value, right? Can you think of any unsigned value which
is also negative?

>> What's the problem that I'm obviously missing?
>>  
>>> When you index a pointer, is the index signed or unsigned?
>> 
>> An index can be either. What's the problem here?
> 
> auto x = p1 - p2;
> 
> What's the type of x?

Is that what you meant by "index a pointer"?

Anyhow, it is a signed value. The difference between any two random memory
addresses can be positive or negative. Whatever the 'signedness' of 'x' is,
the expression "p2 + x == p1" must be true.

If p1 is 0 and p2 is uint.max then 'x' must still be able to hold
(-uint.max)

> Denis Koroskin wrote:
>>> auto x = p1 - p2;
>>>
>>> What's the type of x?
>> 
>> ptrdiff_t, signed counterpart of size_t
>
> Do you really want an error if you go:
>
> size_t y = p1 - p2;

Yes I do.

  size_t y = cast(size_t)p1 - p2; -- No error.
  ptrdiff_t y = p1 - p2; -- No error.
  size_t y = p1 - p2; -- Error.

Safety is supposed to be enhance by using D, is it not?

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell


More information about the Digitalmars-d-announce mailing list