On 15/02/13 10:27, Michiel Konstapel wrote: > And for fun, try the quiz at http://blog.regehr.org/archives/721. > Then cry as you realize how much broken code there must be out > there... >
There are a number of inaccuracies in that quiz. Question 3 asks for the evaluation of "(unsigned short) 1 > -1", and gives the answer as 1. But this is only correct on platforms in which there is an integer size greater than "short" - if not (such as if short and long are both 32-bit, as is the case on some DSPs), then -1 is converted to unsigned and the result is 0. Question 4 makes incorrect assumptions about x86-64 - it assumes there are bigger integer types than "unsigned int". This is the case on Linux (where "long" is 64-bit), but Windows "long" is 32-bit even in 64-bit mode. If you are using a C standard (such as C90) that does not support "long long" (which are 64-bit in Win64), then again you end up with unsigned promotion of -1L. Lots of other questions also make unspecified assumptions about the platform in question (such as assuming 32-bit ints). This of course re-enforces your point - even people who make and publish quizes about the details of int promotion in C get it wrong! (And no doubt someone will find an error in my comments above...) mvh., David ------------------------------------------------------------------------------ Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://p.sf.net/sfu/appdyn_d2d_feb _______________________________________________ Mspgcc-users mailing list Mspgcc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mspgcc-users