3 ms·
The -1 here is hiding the fact that -1 is really just 0xffffffff due to two's complement (architecture dependant of course) And printing it as %d is technicall
by free_bip 3y ago
The -1 here is hiding the fact that -1 is really just 0xffffffff due to two's complement (architecture dependant of course)
And printing it as %d is technically a misuse of printf, since %d means print as a signed integer. If you did %u (print as unsigned integer) instead you'd see the value is really 4,294,967,295 (again, platform dependant)
- robertlagrant 3y agoI knew someone would say this :) But my point is that how can I assign a negative number to an unsigned int in the first place?
- drekipus 3y agoI would argue that you're not. But I use python in my day job
- robertlagrant 3y agoHah yes, me too. Python has the opposite problem. C changes the type of a supplied value to fit the declared variable type. Python changes the type of the variable to fit its value's (or reference's) type. So in C if I assign a char literal to an int, I get an int. If I do the same in Python, I get a string. In a strongly typed language, which I'm defining as "needs the left and right hand side of an assignment expression to match somehow", I'd get a type error.