News for hackers. Stuff that matters.
Re:Unexpected Ways Memory Subsystem Interacts with Branch Pr... by inetknght on Friday December 29, 2023 @12:26PM (#38807614)
cnt += a[i]

No, you've changed the right-hand side expression. Now you're adding a[i] to cnt and nowhere has it stated that a[i] is 1. But a[i] > 0's result is always zero or one.

I suggest what you want is this:

    cnt += !!a[i]
Now, a[i] is not-notted -- the expression returns a bool indicating whether the value is converted to true.

or this, depending on your style:

    cnt += bool(a[i])
which does the same thing

There are no comments on this comment yet.