if(PORTA & 3 != 0)
looks like it should be true if either of the low two bits is set. But actually, it only fires if the low bit is set because this resolves to PORTA & (3 != 0), which is PORTA & 1.
Some C compilers will warn you about this. Embedded C compilers are not usually the sort of compilers that are nice enough to have these warnings.
As a bonus, different languages handle precedence of &,|,^ differently: Python, for instance, binds & more tightly than ==.
And then everyone decides their own languages will copy it forever.
One more for my list of "why I don't like C".
X != Y returns an integer value, no "implicit cast" required for &.
I've never understood why any language does this. To save a few keystrokes? Code is much more read than written.
With this kept in mind, I've personally found almost all the implicit conversions in both languages to be intuitive.
* You can limit the values to numerics, and nowadays use attributes to handle javascript, but that wouldn't help PHP where it gets encoded to querystring anyway.
Beyond that though, most implicit casts are just bad.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."
— Brian W. Kernighan and P. J. Plauger in The Elements of Programming Style.Both of these were bizarre bugs, and neither was immediately evident.
#1 was presented by an error saying something to the effect of "received xXxX bytes, expecting yyyy".
#2 was harder. It became evident because of logging. The high res timer was used gor logging amd intermittently, I was seeing +200 years supposedly elapsed during a db operation. Obviously wrong. It was a bug due to how registers are handled between x86 and x64 code.
He had a compound conditional without enough parentheses in it, and one of the possible outcomes resulted in fd=1, which is stdin on many operating systems. My general advice now is to assume a 5th grade reading level for math (which consists of +-x/), and use parentheses for everything else. Especially if you think yourself to be clever (narrator: he did).