disabling unary "-" for unsigned types

Steven Schveighoffer schveiguy at yahoo.com
Thu Feb 18 11:40:17 PST 2010


On Thu, 18 Feb 2010 14:22:06 -0500, Walter Bright  
<newshound1 at digitalmars.com> wrote:

> Steven Schveighoffer wrote:
>> First, it would work under my rules.  j would be of type int.  Under my  
>> rules, negating an unsigned value equates to a signed version of that  
>> type.
>
>
> I've tried to stick with the principle that C code compiled with D will  
> either work the same, or will fail with a compiler error message. It's  
> very important to avoid "compiles, but produces subtly different  
> behavior" for integer numeric code.
>
> The reason for this is there's a lot of debugged, working C code that  
> contains rather complicated integer expressions. How/why it works may be  
> long since lost information, and having it fail when translated to D  
> will cause frustration and distaste for D.
>
> Changing the signedness of a sub-expression will definitely fall into  
> this category.

This is a much better argument than your previous one.  However, there is  
at least one (and probably more common) case where this is not true:  
statically sized arrays as parameters to functions.

But such changes need good justification for their inclusion.  It's clear  
to me that it's justified on the fact that there is no reasonable use to  
have the negation of an unsigned be unsigned, but it's not my language :)

I guess unary - for unsigned will only ever be a lint-worthy error.

-Steve



More information about the Digitalmars-d mailing list