5 ms·
Third question is wrong. It's implementation defined, because unsigned short might be the same rank as unsigned int in some implementations, in which case it re
by veltas 4y ago
Third question is wrong. It's implementation defined, because unsigned short might be the same rank as unsigned int in some implementations, in which case it remains unsigned when promotion occurs.
- rwmj 4y agoHe does say on the first page: All other things being equal, assume GCC/LLVM x86/x64 implementation-defined behaviors. Are there any normal, modern machines where short and int are the same size? I think the last machine where that was true was the 8086.
- veltas 4y agoOn x86 systems like 8086 short and int were the same size. And that appears to be a footnote they've added after being called out for being wrong. The question gives "implementation defined" as an option and in other questions seems to specify the ABI, and in some assumes it without saying again. Very inconsistent, they should fix their quiz really. The last x86 processor I know of to have these sizes is 80286.
- galangalalgol 4y agoAvr microcontrollers still have 16bit ints, probably 8051 and pic too, but I don't use those. Lots of people do though. TI dsp uses 48 bit long, so don't count on int and long being the same either.
- moefh 4y agoThat's still a bad question: the behavior is implementation-defined according to the standard, so having "implementation-defined" as a wrong option is ambiguous and confusing. The question would be fine (given that note) if "impementation-defined" was not an option, like for example the question about "SCHAR_MAX == CHAR_MAX".
- fuckstick 4y ago> I think the last machine where that was true was the 8086. The last machine with a word size of 16 bits? The 286 was as well. There were others like the WDC 65816 (the Apple IIgs and SNES CPU). It just so happens that there simply far fewer 16 bit CPUs then there were 8 or 32 (or “32/16” like the 68k). Also 8 bit CPUs are simply a poor fit for C by their nature and the assumptions C makes. But the numerous ones still relevant today will use 16 bit ints. The use of Real or V86 mode on the x86 went on for many years after the demise of the 8086. I think it is a somewhat of a joke at this point that they’re teaching Turbo C in some developing countries.
- codeflo 4y agoDefine "machine". All kinds of microcontrollers are programmed with C.
- jwilk 4y agoThey may have the same width, but not the same rank. From C99 §6.3.1.1: > — The rank of long long int shall be greater than the rank of long int, which shall be greater than the rank of int, which shall be greater than the rank of short int, […] > — The rank of any unsigned integer type shall equal the rank of the corresponding signed integer type, if any.
- moefh 4y agoThat's true, but it doesn't matter to the point being made. According to the standard[1], if short and int have the same size (even if not the same rank) both numbers are converted to unsigned int (that is, the unsigned integer type corresponding to int) because int can't represent all values of unsigned short. The usual arithmetic conversions never "promote" an unsigned to signed if doing so would change the value. [1] http://port70.net/~nsz/c/c99/n1256.html#6.3.1.8 http://port70.net/~nsz/c/c99/n1256.html#6.3.1.8
- deleted 4y ago[deleted]