News for hackers. Stuff that matters.
Re:The Little Bool of Doom (2025) by kccqzy on Sunday February 08, 2026 @02:15PM (#46937483)
Excellent debugging journey.

If I were the author, I would skip the part about using the compiler explorer and reading the assembly. When I write C code, I need to satisfy the rules of the C language. Unless I’m debugging the compiler or dealing with performance issues, my experience is that reading the generated assembler and understanding it is usually a slow way of debugging. The author eventually did compile with -fsanitize=undefined but I would honestly do that first. It prints a nice error message about the exact issue as the author has shown.

Re:The Little Bool of Doom (2025) by direwolf20 on Sunday February 08, 2026 @02:18PM (#46937520)
I have to disagree. If you merely want to fix the problem, you can stop as soon as you find something that's awry and whose alteration removes the problem. But don't you want to understand the problem? Don't you want to see how the compiler can reasonably generate code that says a bool variable is true and false at the same time?
Re:The Little Bool of Doom (2025) by kccqzy on Sunday February 08, 2026 @02:54PM (#46937880)
It’s about abstraction layers. Most of the time, understanding the generated assembler code isn’t useful when it comes to understanding the problem. It satisfies my curiosity sure, but the problem is at the C level, an undefined behavior.

Understanding what the C compiler generates is interesting, but without a corresponding intuition about the optimizer passes, such understanding is shallow and unlikely to be generalized to other problems in the future. You probably won’t even remember this the next time you debug another undefined behavior. On the other hand, if you were to know the optimizer passes employed by the compiler and could deduce this code from that, then it is a useful exercise to enhance your intuition about them.

Re:The Little Bool of Doom (2025) by exmadscientist on Sunday February 08, 2026 @04:29PM (#46938677)
I think it depends on your experience. I have a lot of experience from the Old Days™ and from developing for microcontrollers, so I find reading assembly very natural and straightforward. When coding for the really small MCUs I've often had the disassembly generated and shown on another window every time I incrementally build, and can check and make sure it's what I was expecting to see.

I do agree that knowledge of compiler optimizations is really important to working this way, though you'll eventually pick them up anyway. I don't see much value in looking at -O0 or -Og disassembly. You want the strongest stuff the compiler can generate if you're going to do this, which is usually either -O3 or -Oz (both of which are strong in their own ways). -O0 disassembly is... just so much pain for so little gain. Besides, -O3 breaks more stuff anyway!

For someone without this level of experience (and who isn't interested in learning)... yeah, I can see why you'd want to do this another way. But if you've got the experience already, it's plenty fast enough.

Re:The Little Bool of Doom (2025) by lmm on Sunday February 08, 2026 @08:34PM (#46940553)
The thing is, you're gaining a bunch of knowledge about compiler internals and optimisations, but those aren't necessarily specified or preserved, so it's questionable how valuable that experience actually is. The next release of the compiler might rewrite the optimiser, or introduce a new pass, and so your knowledge goes out of date. And even if you have perfect knowledge of the optimiser and can write code that's UB according to the standard but will be optimised correctly by this specific compiler... would that actually be a good idea?

All of that is less true in the microcontroller world where compilers change more slowly and your product will likely be locked to a specific compiler version for its entire lifecycle anyway (and certainly you don't have to worry about end users compiling with a different compiler). In that case maybe getting deeply involved in your compiler's internals makes more sense.

Re:The Little Bool of Doom (2025) by exmadscientist on Monday February 09, 2026 @01:19AM (#46942131)
Learning about how compilers optimize code isn't really knowledge that goes out of date. Yes, things get reshuffled or new ideas appear, but everything builds on what's already there.

You'd never want (except in extreme desperation) to use this knowledge to to justify undefined behavior in your code. You use it to make sure you don't have any UB around! Strategies like "I wrote a null pointer check, why isn't it showing up anywhere in the assembly?" can be really helpful to resolve problems.

Re:The Little Bool of Doom (2025) by direwolf20 on Monday February 09, 2026 @06:16AM (#46944011)
You're not just learning the specific thing this compiler does on this code, but also the sorts of things compilers can do, in general.
Re:The Little Bool of Doom (2025) by niobe on Sunday February 08, 2026 @04:35PM (#46938740)
I think that's the kind of intuitive decision that comes from years of troubleshooting experience. It's not obvious that would be the place to start. It's impressive to me at least he got there.
Re:The Little Bool of Doom (2025) by pseudohadamard on Monday February 09, 2026 @04:54AM (#46943507)
The author knew there was a problem, knew where the problem was, and knew what the problem was, but even with that and an extensive perusal of the standard he still only thinks he knows what part of the standard was violated, presumably because nothing else fit ("didn't explicitly say anything about invalid _Bool values. After some more searching, I believe I've found my answer"). There's no way anyone without omniscience could have predicted this obscure issue being present somewhere in Doom's 60,000 lines of code.
Re:The Little Bool of Doom (2025) by saagarjha on Monday February 09, 2026 @06:03AM (#46943921)
With the behavior specified UB sanitizer would have been my first tool to try.
Re:The Little Bool of Doom (2025) by adrian_b on Monday February 09, 2026 @08:45AM (#46945123)
Presumably also the author has now learned this, after discovering at the end that compiling with the sanitizer enabled immediately showed which is the bug, which would have saved a lot of time if he had always used it.
Re:The Little Bool of Doom (2025) by turol on Wednesday February 11, 2026 @11:33AM (#46977106)
Unfortunately Doom has a lot of undefined behavior (because it's a 30 year old codebase) so if you enable UBSAN you're inundated with warnings. Finding this specific needle in that haystack would take quite a lot of effort.