Jump to page: 1 215  
Page
Thread overview
[OT] The Usual Arithmetic Confusions
Jan 28, 2022
Paul Backus
Jan 28, 2022
H. S. Teoh
Jan 28, 2022
forkit
Jan 28, 2022
forkit
Jan 28, 2022
Paulo Pinto
Jan 28, 2022
deadalnix
Jan 29, 2022
Siarhei Siamashka
Jan 29, 2022
Siarhei Siamashka
Jan 30, 2022
Nick Treleaven
Jan 31, 2022
Elronnd
Jan 31, 2022
Elronnd
Jan 31, 2022
Elronnd
Jan 31, 2022
Elronnd
Jan 31, 2022
Paulo Pinto
Jan 31, 2022
Paulo Pinto
Feb 02, 2022
Dukc
Feb 03, 2022
Dukc
Feb 03, 2022
Dukc
Feb 03, 2022
Dukc
Feb 03, 2022
Dukc
Feb 03, 2022
Dukc
Feb 03, 2022
Paul Backus
Jan 30, 2022
Ivan Kazmenko
Feb 02, 2022
Dukc
Feb 02, 2022
Walter Bright
Feb 02, 2022
Adam Ruppe
Feb 03, 2022
Walter Bright
Feb 03, 2022
Siarhei Siamashka
Feb 03, 2022
Walter Bright
Feb 03, 2022
Paul Backus
Feb 04, 2022
Walter Bright
Feb 04, 2022
Paulo Pinto
Feb 04, 2022
Adam D Ruppe
Feb 04, 2022
Walter Bright
Feb 04, 2022
H. S. Teoh
Feb 04, 2022
Walter Bright
Feb 17, 2022
deadalnix
Feb 04, 2022
Paul Backus
Feb 04, 2022
H. S. Teoh
Feb 04, 2022
Walter Bright
Feb 04, 2022
Paul Backus
Feb 04, 2022
Paul Backus
Feb 04, 2022
Elronnd
Feb 04, 2022
Walter Bright
Feb 04, 2022
Elronnd
Feb 05, 2022
Walter Bright
Feb 05, 2022
Timon Gehr
Feb 05, 2022
Walter Bright
Feb 05, 2022
Timon Gehr
Feb 05, 2022
Walter Bright
Feb 05, 2022
Walter Bright
Feb 06, 2022
Timon Gehr
Feb 06, 2022
Walter Bright
Feb 06, 2022
Timon Gehr
Feb 05, 2022
Max Samukha
Feb 04, 2022
Siarhei Siamashka
Feb 04, 2022
Walter Bright
Feb 05, 2022
Siarhei Siamashka
Feb 05, 2022
Walter Bright
Feb 05, 2022
Walter Bright
Feb 05, 2022
Siarhei Siamashka
Feb 04, 2022
Mark
Feb 04, 2022
H. S. Teoh
Feb 04, 2022
Walter Bright
Feb 05, 2022
Mark
Feb 03, 2022
Adam D Ruppe
Feb 04, 2022
Walter Bright
Feb 04, 2022
Adam D Ruppe
Feb 04, 2022
Walter Bright
Feb 04, 2022
Adam Ruppe
Feb 04, 2022
Adam Ruppe
Feb 05, 2022
Walter Bright
Feb 05, 2022
Siarhei Siamashka
Feb 05, 2022
Adam D Ruppe
Feb 06, 2022
jmh530
Feb 05, 2022
Walter Bright
Feb 20, 2022
Dukc
Feb 04, 2022
Elronnd
Feb 05, 2022
Walter Bright
Feb 04, 2022
Siarhei Siamashka
Feb 04, 2022
Guillaume Piolat
Feb 17, 2022
bachmeier
Feb 17, 2022
Elronnd
Feb 17, 2022
bachmeier
Feb 17, 2022
Paul Backus
Feb 17, 2022
forkit
Feb 17, 2022
forkit
Feb 17, 2022
Paul Backus
Feb 18, 2022
forkit
Feb 18, 2022
Paul Backus
Feb 18, 2022
forkit
Feb 17, 2022
Walter Bright
Feb 17, 2022
Paul Backus
Feb 17, 2022
bachmeier
Feb 17, 2022
Walter Bright
Feb 18, 2022
Paul Backus
Feb 18, 2022
deadalnix
Feb 18, 2022
Walter Bright
Feb 18, 2022
Walter Bright
Feb 18, 2022
Timon Gehr
Feb 18, 2022
Walter Bright
Feb 18, 2022
Timon Gehr
Feb 21, 2022
Siarhei Siamashka
Feb 18, 2022
Nick Treleaven
Feb 18, 2022
Nick Treleaven
Feb 18, 2022
Timon Gehr
Feb 18, 2022
Walter Bright
January 28, 2022

https://shafik.github.io/c++/2021/12/30/usual_arithmetic_confusions.html

>

There are a lot of aspects of C++ that are not well understood and lead to all sorts of confusion. The usual arithmetic conversions and the integral promotions are two such aspects. [...] This is one of the areas in C++ that comes directly from C, so pretty much all of these examples applies to C as well as C++.

Unfortunately, this is also one of the areas of D that comes directly from C, so D programmers have to watch out for these as well.

It's been argued in the past, on these forums, that these conversions are "just something you have to learn" if you want to do system-level programming. But if C++ programmers are still getting this stuff wrong, after all these years, perhaps the programmers aren't the problem. Is it possible that these implicit conversions are just too inherently error-prone for programmers to reliably use correctly?

January 27, 2022
On Fri, Jan 28, 2022 at 02:15:51AM +0000, Paul Backus via Digitalmars-d wrote:
> https://shafik.github.io/c++/2021/12/30/usual_arithmetic_confusions.html
[...]
> Unfortunately, this is also one of the areas of D that comes directly from C, so D programmers have to watch out for these as well.
> 
> It's been argued in the past, on these forums, that these conversions are "just something you have to learn" if you want to do system-level programming. But if C++ programmers are still getting this stuff wrong, after all these years, perhaps the programmers aren't the problem. Is it possible that these implicit conversions are just too inherently error-prone for programmers to reliably use correctly?

I agree.  The question, though, is how to convince Walter. :-P


T

-- 
Старый друг лучше новых двух.
January 28, 2022
On Friday, 28 January 2022 at 02:15:51 UTC, Paul Backus wrote:
>
> Unfortunately, this is also one of the areas of D that comes directly from C, so D programmers have to watch out for these as well.
>
> It's been argued in the past, on these forums, that these conversions are "just something you have to learn" if you want to do system-level programming. But if C++ programmers are still getting this stuff wrong, after all these years, perhaps the programmers aren't the problem. Is it possible that these implicit conversions are just too inherently error-prone for programmers to reliably use correctly?

I would really like a compile time option, that outputs warnings on implicit conversions (just warnings, not errors). It should still compile nonetheless.

I would use that feature, a lot!

January 28, 2022
On Friday, 28 January 2022 at 03:44:25 UTC, forkit wrote:
>

-profile=implicitConversions


January 28, 2022
On Friday, 28 January 2022 at 02:33:18 UTC, H. S. Teoh wrote:
> On Fri, Jan 28, 2022 at 02:15:51AM +0000, Paul Backus via Digitalmars-d wrote:
>> https://shafik.github.io/c++/2021/12/30/usual_arithmetic_confusions.html
> [...]
>> Unfortunately, this is also one of the areas of D that comes directly from C, so D programmers have to watch out for these as well.
>> 
>> It's been argued in the past, on these forums, that these conversions are "just something you have to learn" if you want to do system-level programming. But if C++ programmers are still getting this stuff wrong, after all these years, perhaps the programmers aren't the problem. Is it possible that these implicit conversions are just too inherently error-prone for programmers to reliably use correctly?
>
> I agree.  The question, though, is how to convince Walter. :-P
>
>
> T

Now that we have importC, the argument for easier porting C to D code is less valid. D no longer needs to closely follow the usual arithmetic "confusions" of C, just so that some C code can have the same meaning when copied to D. I prefer to get compliler errors when porting C to D than preserving the landmines from the original code.
January 28, 2022

On Friday, 28 January 2022 at 03:46:00 UTC, forkit wrote:

>

[..]
-profile=implicitConversions

Nit: I think it should be -vimplicit-conversions, as the other diagnostic switches start with -v (-vtls, -vtemplates, -vgc, etc). You can see the docs here:

https://dlang.org/dmd-linux.html

January 28, 2022

On Friday, 28 January 2022 at 02:15:51 UTC, Paul Backus wrote:

>

https://shafik.github.io/c++/2021/12/30/usual_arithmetic_confusions.html

>

There are a lot of aspects of C++ that are not well understood and lead to all sorts of confusion. The usual arithmetic conversions and the integral promotions are two such aspects. [...] This is one of the areas in C++ that comes directly from C, so pretty much all of these examples applies to C as well as C++.

Unfortunately, this is also one of the areas of D that comes directly from C, so D programmers have to watch out for these as well.

It's been argued in the past, on these forums, that these conversions are "just something you have to learn" if you want to do system-level programming. But if C++ programmers are still getting this stuff wrong, after all these years, perhaps the programmers aren't the problem. Is it possible that these implicit conversions are just too inherently error-prone for programmers to reliably use correctly?

Not surprisingly, the system programming languages outside C family tend to go with explicit conversions.

January 28, 2022

On Friday, 28 January 2022 at 02:15:51 UTC, Paul Backus wrote:

>

https://shafik.github.io/c++/2021/12/30/usual_arithmetic_confusions.html

For what it is worth, the first exemple is fixed in D.

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.

January 29, 2022

On Friday, 28 January 2022 at 18:39:54 UTC, deadalnix wrote:

>

The other ones really banal wrap around behavior, which your really can't do without if youw ant to make anything fast, IMO.

Modern programing languages tend to have separate operators or intrinsincs for wrapped and non-wrapped (trap on overflow) arithmetic operations. In the vast majority of cases having an arithmetic overflow is a bug in the code. And being able to catch such bugs is as useful as having bounds checking for arrays. I think that it's only a matter of time until processors start adding the missing instructions to make this fast. That's a typical chicken/egg problem. If Rust language becomes really popular, then the hardware will adapt.

January 29, 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:

>

https://shafik.github.io/c++/2021/12/30/usual_arithmetic_confusions.html

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 advantages of using TypeScript over javascript and Python with PyCharm as well.

Unfortunately the syntax for warning silencing is often just an afterthought... It should be part of language-design in my opinion.

>

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 signedness.

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.

« First   ‹ Prev
1 2 3 4 5 6 7 8 9 10 11