[OT] The Usual Arithmetic Confusions
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Sat Jan 29 10:16:00 UTC 2022
On Friday, 28 January 2022 at 18:39:54 UTC, deadalnix wrote:
> On Friday, 28 January 2022 at 02:15:51 UTC, Paul Backus wrote:
> For what it is worth, the first exemple is fixed in D.
For C++ this is fixed with warnings, e.g. -Wconversion
People can choose their own level of strictness in C++. Of
course, if you use templated libraries then you might get
warnings you don't want. So having a good syntax for silencing
warnings inline is an important language design issue, because
then you are encouraged to turn on maximum strictness and just
selectively disable it where it is convenient.
Warnings with inline-silencing is actually one of the main
PyCharm as well.
Unfortunately the syntax for warning silencing is often just an
afterthought... It should be part of language-design in my
> The multiplication one is particularly interesting. The other
> ones really banal wrap around behavior, which your really can't
> do without if youw ant to make anything fast, IMO.
> I'm surprised there aren't more exemple of signed -> unsigned
> conversion because that one is a real mind fuck.
I actually can't remember having these issues in my own code, it
isn't really all that difficult to get these right. But you have
to pay special attention to these things when writing templates,
fortunately you can restrict templated parameters based on
The only case that I can remember where this turned into a
headache was with signed modulo operator, but it was resolved by
writing my own overloaded "modulo(x,y)" function.
Of course, if you don't enable warnings you've basically said you
are ok with the semantics of a lazy 1970s approach designed to
make it possible to write really terse code. People get what they
ask for by choosing terseness.
More information about the Digitalmars-d