News for hackers. Stuff that matters.
Re:Bug #915: Solved by nneonneo on Tuesday January 14, 2020 @07:40PM (#22050752)
The very low precedence of & is the source of an unbelievable number of bugs, especially in embedded programming. For example:

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 ==.

Re:Bug #915: Solved by Dylan16807 on Wednesday January 15, 2020 @02:34AM (#22052366)
It's a shame. C made the precedence blatantly wrong so a few thousand lines of legacy code wouldn't have to be updated.

And then everyone decides their own languages will copy it forever.

Re:Bug #915: Solved by Cthulhu_ on Wednesday January 15, 2020 @03:24AM (#22052566)
That should give a warning at least because it (and this is probably a C thing) treats or implicitly casts a boolean true / false to a 0/1. You shouldn't be able to do PORTA & true.

One more for my list of "why I don't like C".

Re:Bug #915: Solved by bigpeet on Wednesday January 15, 2020 @03:42AM (#22052639)
Depending on what version of C you are using, there are no "boolean" values.

X != Y returns an integer value, no "implicit cast" required for &.

Re:Bug #915: Solved by chopin on Wednesday January 15, 2020 @04:18AM (#22052823)
Implicit casts are both convenient and evil. JavaScript deserves its own place for it.

I've never understood why any language does this. To save a few keystrokes? Code is much more read than written.

Re:Bug #915: Solved by Izkata on Wednesday January 15, 2020 @08:47AM (#22054047)
Javascript and PHP deal with HTML, where input forms can only request text* but are often used for numbers, so the conversion rules are an attempt to automatically treat numbers as numbers instead of forcing programmers to always do the conversion themselves (as other frameworks rely on instead).

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.

Re:Bug #915: Solved by rocqua on Wednesday January 15, 2020 @06:49AM (#22053447)
In most cases, up or down casting 32 and 64 bit integers would be a shitton of work that barely adds anything. A similar case could be made for casting ints to floats (i.e. 2 + 3.1 should just work).

Beyond that though, most implicit casts are just bad.