4 ms·
Had to fix a Samsung kernel driver once because their temperature sensor driver stored the measured temperature in Celsius in an unsigned char. Meaning, of cou
by DagAgren 7y ago
Had to fix a Samsung kernel driver once because their temperature sensor driver stored the measured temperature in Celsius in an unsigned char.
Meaning, of course, that if the processor was ever below freezing, it would think it was running at over 200 degrees, and turn every clock it could find down as far as possible because it thought it was about to catch on fire.
- pjmlp 7y agoGosling on why Java does not do unsigned arithemtic as primitive type. > In programming language design, one of the standard problems is that the language grows so complex that nobody can understand it. One of the little experiments I tried was asking people about the rules for unsigned arithmetic in C. It turns out nobody understands how unsigned arithmetic in C works. There are a few obvious things that people understand, but many people don't understand it. https://www.artima.com/intv/gosling3.html https://www.artima.com/intv/gosling3.html
- touisteur 7y agoI miss the uint_64 or uint_32 in Java. It's annoying since the world of C talks in unsigned a lot on network protocols.
- pingyong 7y agoHm, I wonder what kind of questions that entailed. Because unsigned arithmetic in C seems very intuitive to me. I have a hard time coming up with a question that would be hard to answer. Certainly, if we're talking about the C standard, unsigned integers are much more intuitive than signed integers. Although even if there somehow are hard questions, I'm not sure understanding unsigned arithmetic would have helped whoever wrote that code. Because I think if you asked that person "what does this unsigned type do with -5 C?" the answer would have been pretty obvious.
- pjmlp 7y agoYou might not have any issue dealing with it, but are you sure that everyone on a given team, specially when scaled into off-shoring teams of various skill levels, all will master it? I have been coding since the mid-80's and I wouldn't definitely assert that I know it well, without having a look into ISO C standard and the semantic expectations of the abstract C machine and implementation specific behaviors.
- mantap 7y agoThe problem is that programmers tend to confuse the concept of unsigned integers and non-negative integers. They think that just because a number can never be negative it is OK to use an unsigned integer to represent it. This leads to lots of mixed arithmetic of unsigned and signed types which leads to subtle bugs because neither is a subset of the other.
- DmitryOlshansky 7y agoUsually things like: 1u < -1 But more subtle when you have: a.size() - 1 < len
- slrz 7y agoANSI C heavily mixed up the conversion rules for expressions involving both, signed and unsigned, integer types (value-preserving vs. unsigned-preserving in K&R C). This might have been a factor here, given that most of Gosling's peers back then were probably still more familiar with K&R C and its different set of conversion rules.