“I don’t know” is not the right answer. I do know. I know the answer to be “Unspecified”.
But you _don't_ know what it returns, because the behavior is either undefined or implementation defined, and you don't know the implementation.
So you think you know C? (2016)
41–50 of 344 posts
Re: So you think you know C? (2016)
#42There is a minor error in the explanation for the third one: the minimum allowed value for CHAR_BIT in C is 8 (it does not affect the result, principally because the value of ' ' could be anything in the range of char).
Re: So you think you know C? (2016)
#43There are a few problems with the questionnaire. "I don't know" is pretty generic choice to be given/choosen. Say for example, in question 5, the statement "return i++ + ++i;" is undefined, because the value of i is read and modified twice in a single sequence point (and of course, the order of addition is unspecified), which is not allowed in C. So the answer is "Undefined." (The explanation given in the page not ac…
The code is undefined, but "I don't know." is still the correct answer for what happens to the variable.
Re: So you think you know C? (2016)
#44“I don’t know” is not the right answer. I do know. I know the answer to be “Unspecified”.
Re: So you think you know C? (2016)
#45Re: So you think you know C? (2016)
#46To be honest if was pretty obvious what the right answer was, but tried to answer honestly anyway ;)
Re: So you think you know C? (2016)
#47There are a few problems with the questionnaire. "I don't know" is pretty generic choice to be given/choosen. Say for example, in question 5, the statement "return i++ + ++i;" is undefined, because the value of i is read and modified twice in a single sequence point (and of course, the order of addition is unspecified), which is not allowed in C. So the answer is "Undefined." (The explanation given in the page not ac…
> So the answer is "Undefined." The code is undefined, but "I don't know." is still the correct answer for what happens to the variable.
Well, then a better choice would be "I can't know."
Re: So you think you know C? (2016)
#48This is a perfect example of what I hate about some tests. Didn't quite know the purpose of the test, there's a difference between code for any machine and any compiler and gcc running on some vanilla x86, which is pretty common, and could have been the content (ex: you say it's undefined, that's obvious, everyone knows that already, but it's still deterministic... Here's a breakdown of what happens in practice, blah…
Re: So you think you know C? (2016)
#491. 8 (https://godbolt.org/z/Udcuj0)
2. 0 (https://godbolt.org/z/kZz1YQ)
3. -96 (https://godbolt.org/z/1Xq_Oo)
4. 1 (https://godbolt.org/z/MIo0s_)
5. 2 (https://godbolt.org/z/J0dsVW)
I agree, you can argue that it's unspecified, undefined, or whatever. It might not be well defined by the C specification, but none of these programs produce surprising output. Programming in the real world requires that you are able to read and write code like this, even if it requires that you investigate (and depend) the specific behaviour of your compiler/platform.
Re: So you think you know C? (2016)
#50On a typical modern arch, there are consistent and reasonable answers: 1. 8 ( https://godbolt.org/z/Udcuj0 ) 2. 0 ( https://godbolt.org/z/kZz1YQ ) 3. -96 ( https://godbolt.org/z/1Xq_Oo ) 4. 1 ( https://godbolt.org/z/MIo0s_ ) 5. 2 ( https://godbolt.org/z/J0dsVW ) I agree, you can argue that it's unspecified, undefined, or whatever. It might not be well defined by the C specification, but none of these programs produce…
Perhaps “produce consistent results” would be more appropriate.