NHacker Next
  • new
  • past
  • show
  • ask
  • show
  • jobs
  • submit
The Little Bool of Doom (blog.svgames.pl)
kccqzy 30 minutes ago [-]
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.

direwolf20 26 minutes ago [-]
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?
Joker_vD 27 minutes ago [-]
> 1. Explicitly set the C standard to C17 or older, so the code is built using the custom boolean type.

> Option 1) seemed like the easiest one, but it also felt a bit like kicking the can down the road – plus, it introduced the question of which standard to use.

Arguably, that's the sanest one: you can't expect the old C code to follow the rules of the new versions of the language. In a better world, each source file would start with something like

    #pragma lang_ver stdc89
and it would automatically kick off the compatibility mode in the newer compilers, but oh well. Even modern languages such as Go miss this obvious solution.

On the topic of the article, yeah, sticking anything other than 0 or 1 into C99 bool type is UB. Use ints.

Tuna-Fish 10 minutes ago [-]
Rust does the right thing, with the per-crate

    edition =
statement.
theamk 16 minutes ago [-]
This brings memories - back when I was a student programming in Turbo Pascal 6, I got the same invalid bool (due to array range overflow) which was both true and false at the same time.
djoldman 41 minutes ago [-]
> For this, I used the Godbolt compiler explorer.

> Ah-ha! The generated instructions were ever so slightly different. This would be great news, if it wasn't for me forgetting about one little detail: I have zero knowledge of x86 assembly.

Lol'd at this. I've been there: "ah hah! I found you. hrm, now what does this mean..."

TFA makes me thankful my work doesn't involve C / C++. Learning it earlier in life was enough.

43 minutes ago [-]
Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact
Rendered at 19:45:12 GMT+0000 (Coordinated Universal Time) with Vercel.