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
It's so irritating that something as simple as logical and/or isn't the same in different languages :/
In some languages 0 or 5 is 1, in others 0 or 5 is 5
@eniko Sorry "I am TOO OLD SKOOL" ( and mostly C/C++/ASM only ) .. WHAT LANGUAGE on Earth has a 0 || 5 = 5 ??! 😱
@gilesgoat @eniko JavaScript 😬
@gilesgoat @eniko many languages say that "a or b" is the first "truthy" of the two expressions. What "falsy/truthy" is, is a different can of worms.
@Xarizzar @gilesgoat and lua
@Xarizzar @gilesgoat @eniko That is probably the most annoying feature of JavaScript I ever experienced. I am old-school and learned that "0 || 5 == 1 (true)", as defined by Boolean Algebra, but then I saw how it was used in some JavaScript-code and my brain exploded.
Using it instead of "0? 0:5" is really annoying, especially since JS has the "?"-op.
@gilesgoat To be fair, at that point, just use parenthesis, and/or maybe actual if statements, no? Sometimes programming is a work of art but damn if we all don't need to be a little bit more clear in our code at times, hahaha
@Xarizzar in other words KISS ( Keep It Simple and Stupid ) and don't use "exclusive features" that only some languages have ? 🙂
@eniko @Xarizzar @gilesgoat and python, and perl, and pretty much any of the "lisp but with syntax" languages.
@deshipu @eniko @Xarizzar At this point better those STRONG IMPERATIVE languages a la' VHDL/PASCAL where if you do a thing like NUMERIC OR NUMERIC the result is NUMERIC ( i.e. bitwise OR ) BOOLEAN OR BOOLEAN and result can be only TRUE or FALSE (0/1) and you CAN NOT do a thing like NUMERIC OR BOOLEAN ( or else ) unless you cast types so they are the same so "(BOOLEAN) a OR b" or instead "a OR (NUMERIC) b" and if b is BOOLEAN its cast can only be numerically 0 or 1 ( or something like that ).
@gilesgoat don't shout