I dont suppose there's any way to do logical and/or in C without coercing the result to 0 or 1?
I.e. `0 || 5` would result in 5, not 1
I dont suppose there's any way to do logical and/or in C without coercing the result to 0 or 1?
I.e. `0 || 5` would result in 5, not 1
@eniko What context is this in/which problem are you trying to solve?
Certainly, short-circuiting and non-booleans might have some low-level utility, but I'm not seeing it off-hand. I'm curious about what you need to do (although that might not help provide a better answer :(
@eniko your question is very interesting, thanks- I'm having fun poking with Godbolt and learning that && and || seem to always generate branching (gcc and clang, x86 and aarch64), and now I'm wondering why they would define them to always return 0 and 1 and not make it implementation-dependant.
(But then, I know nothing about C, so what do I know.)
@eniko you may have found https://cs.stackexchange.com/questions/155125/in-c-why-limit-and-to-evaluate-to-booleans already, which I found interesting (esp. the use of __typeof__ to define the macro).