Note that this is explicitly comparing two values, which is very different from checking whether a single value is true. Surely you wouldn't expect -1 == 0 to evaluate to true.
> Surely you wouldn't expect -1 == 0 to evaluate to true.
I wouldn't, no - but that's exactly what's happening in the test case.
Likewise, I wouldn't expect -1 == 1 to evaluate to true, but here we are.
The strict semantics of the new bool type may very well be "correct", and the reversed-test logic used by the compiler is certainly understandable and defensible - but given the long-established practice with integer types - i.e "if(some_var) {...}" and "if(!some_var) {...}" - that non-zero is "true" and zero is "false", it's a shame that the new type is inconsistent with that.
Yikes. I think this article undersells the point somewhat. This line of code undermines the type system by spraying -1's into an array of structs, so the only surprise to me is that it took this long to break.
typedef struct
{
// If false use 0 for any position.
// Note: as eight entries are available,
// we might as well insert the same name eight times.
boolean rotate;
// Lump to use for view angles 0-7.
short lump[8];
// Flip bit (1 = flip) to use for view angles 0-7.
byte flip[8];
} spriteframe_t;
which is okay to splat with all-ones as long as `boolean` is either a typedef for a fundamental type(*) or an enum – because C enums are just ints in a trenchcoat and have no forbidden bit patterns! The C99 `bool`/`_Bool` is, AFAICS, the first type in C that has fewer values than possible bit patterns.
So yeah, on C99 and C++ this always had UB and could've broken at any time – though I presume compiler devs were not particularly eager to make it ill-behaved just because. But in pre-C99 it's entirely fine, and `rotate == true || rotate == false` could easily be false without UB.
---
(*) other than `char` for which setting the MSB is… not UB but also not the best idea in general.
And, indeed, if you look at the author's writeup, you see exactly that the generated code satisifes `(rotate == true || rotate == false) == false`, since rotate is checked explicitly against 0 and 1. The essence of the difference is:
> When boolean is an enum, the compiler does exactly what I expected – the == false condition checks if the value is equal to 0, and the == true condition checks if the value is equal to 1.
> However, when boolean is actually _Bool, the == false check is transformed into != 1, and the == true check is transformed into != 0 – which makes perfect sense in the realm of boolean logic. But it also means that for a value of 255, hilarity ensures: since 255 is neither 0 nor 1, both conditions pass!
So a value of 255 also makes both checks fail for the enum, but because of the ordering of the code, it was expected to evaluate as != false.
Had the check:
```
if (sprtemp[frame].rotate == false)
```
been written as:
```
if (sprtemp[frame].rotate != true)
```
then it would work for the `bool` type, but not the `enum` type, at least in C23 mode. Assumedly the C++ mode (effectively) treated the boolean as an enum, or possibly as `false == 0`, `true != 0`.
C has no particularly strong type system, and it works on typical platforms with all types up to the introduction of _Bool. And maybe float/double, but I think it gives a NaN.
> Anxiety is the second leading cause of disability and mortality worldwide.
I think this comes from WHO, but isn't consistent with other information from WHO, so it's pretty debatable.
I believe the source is this[0], which says "Mental health conditions such as anxiety and depression are highly prevalent in all countries and communities, affecting people of all ages and income levels. They represent the second biggest reason for long-term disability, contributing to loss of healthy life."
However, elsewhere on their site[1], WHO lists the top 3 global causes of death and disability in 2021 as heart disease, COVID-19, and stroke.
No, its very reliable after consideration for how anxiety works from a physiological perspective and what does to a person's health and how modifies their decisions and behaviors. When all these factors are taken into account anxiety alone may account for most other more directly measured mortality conditions.
The other side of that coin is that anxiety is also most prominently the result of social conditioning as opposed to diagnosed illness. This results in anti-anxiety medications that are vastly over-prescribed for individuals that receive less than ideal benefits.
There’s an implicit assumption in this snark that the only purpose of a law is to create legal consequences (a subclass of error that’s very common on this forum, some type of “literalism”).
This is IMO a bit shortsighted: laws impact culture, laws represent ideals worth striving for, and in a democracy, laws help define the type of society in which the people would like to live.
A law’s utility is not limited to its ability to be enforced. In fact, in a democracy, when a law is not enforced, it is a strong signal that the will of the people is not being carried out by those charged with enforcement. See: the current USDOJ.
That's not the norm or an expectation in question, though. People get away with breaking laws all the time. It's very common. But the fact that something is illegal by itself exerts a psychological effect that sets an expectation and modulates the Overton window of the perceived norm. Such laws also enable enforcement. It is untrue that unless a law is perfectly enforced, it is useless or bad.
But you would agree that, despite the DEA not raiding dispensaries in legal states, the fact that marijuana is still a Schedule 1 drug still has some meaning? It’s almost retained as a pretense to keep certain prisoners behind bars despite the rest of society kind of moving on from the Reagan-era propaganda. So even though non-enforcement is the norm and expectation, the law still has an impact on society.
The purposes and effects of laws are complicated. This thread started because someone blithely claimed that the US is in a better situation because they have no laws concerning privacy because GPDR is difficult to enforce. I’m pushing back against that (as a US citizen) because it’s a damaging and myopic viewpoint that may or may not be based in American exceptionalism or techbro cynicism or something else entirely.
This seemed like a bad idea to me from the beginning. Giving personal biometric details to a monster corporation is a nonstarter for both techies and normies.
I agree in theory, but yet I have an iPhone, and Apple is managing my biometrics.
I do not have Clear, or TSA preCheck, etc. but still my biometrics are in the US database.
So, in practice, I am not sure if that is truly a non-starter for "normies" and even some "techies". I already gave up on my face biometrics living in US.
How else can you patch an exploit if you don't try it first? The first step in reverse engineering malware is to try the exploit in a controlled environment.
My fingerprints and palmprints have gone through so many biometric studies through multiple colleges and I know they’ve done experiments with copying and making false biometrics from some of their study samples.
reply