Should negating an unsigned integral be an error?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Mon Jan 29 10:06:41 UTC 2018


On Monday, January 29, 2018 09:58:00 Dave Jones via Digitalmars-d wrote:
> Given
>
> uint i = 12345;
>
> should
>
> writeln(-i)
>
> be an error? or maybe i should be automatically cast to a larger
> signed type?

It arguably should be, but it's pretty common in C/C++ to get uint.max with
-1, and I suspect that it's fairly common in D as well even though you could
just use uint.max. So, it could be argued either way.

- Jonathan M Davis



More information about the Digitalmars-d mailing list