News for hackers. Stuff that matters.
Re:Zig 0.7.0 tagged by dnautics on Sunday November 08, 2020 @04:50PM (#25029408)
There's slightly different looking operators if you want explicit overflow behaviour, where it's not UB.
Re:Zig 0.7.0 tagged by Gibbon1 on Sunday November 08, 2020 @06:19PM (#25030014)
I keep coming back to the idea that you should let the user decide. And optimizing on UB by default is always the wrong thing. Because for 99% of code performance is secondary to correctness. The compiler should only do that when requested.

A point: Benchmarks produce metrics measured in seconds. Bugs don't produce metrics you can measure but the costs are unbounded.

Re:Zig 0.7.0 tagged by simias on Monday November 09, 2020 @08:01AM (#25034302)
>I keep coming back to the idea that you should let the user decide. And optimizing on UB by default is always the wrong thing.

Aren't you contradicting yourself here?

And I do think that some UB optimizations make a lot of sense. Actually if you look at the way Rust does it, it gets rid of many UBs not by adding checks for them but by explicitly forbidding the UB condition to occur in safe code (therefore "optimizing on UB" by enforcing that the UB condition cannot happen in correct code, not by adding checks for it and slowing things down). That's why for instance pointer arithmetic is unsafe in Rust, since arbitrary pointer offsets can lead to UB.

Although I agree that there are a few C UBs that I think ought to be relaxed because they don't make a lot of sense for modern architectures though (signed overflow being the main one).

Re:Zig 0.7.0 tagged by Gibbon1 on Monday November 09, 2020 @01:26PM (#25037880)
I just draw on firmware that I write for micro-controllers. Most of the code isn't in a hot path. There is probably 100 lines worth out of 50,000. That's what I mean by optimizing on UB by default at least in my case seems wrong. I'm also in the apposite situation from a web service where if a worker thread hangs you just kill it and restart it. And you can push update to the cloud.

Bringing up signed overflow. I did some tests once flipping back and forth between using a int and an unsigned int and wasn't impressed with the speed up. I've also done tests with aligned and an packed data structures and on a modern processor, also not impressed.

Re:Zig 0.7.0 tagged by wtetzner on Monday November 09, 2020 @04:29PM (#25040167)
> Aren't you contradicting yourself here?

I don't think it's a contradiction. I think what's being said is that it's the wrong default, i.e. the special different-looking operators should be the ones with UB, not the obvious "normal"-looking ones.

Re:Zig 0.7.0 tagged by Gibbon1 on Monday November 09, 2020 @05:29PM (#25040734)
Exactly. At least my experience there is code where you really care about performance and you are willing to do the distance. And then there is a lot of code where you just want it to work with no surprises.