5 ms·
If you write a quiz like this, and "Don't Know" is an answer but "Undefined Behavior" and "Implementation-Dependent" are left off, you're doing it wrong.
by awalton 10y ago
If you write a quiz like this, and "Don't Know" is an answer but "Undefined Behavior" and "Implementation-Dependent" are left off, you're doing it wrong.
- simosx 10y agoPeople would figure it out from the start if "Implementation-Dependent" was an option. Perhaps a "Something else" would be more appropriate so that the reader would still be surprised at the end and feel it was a decent multiple-choice test.
- sqeaky 10y agoIt is likely that the state of someone's knowledge is "don't know" regardless of the actual state of affairs. If a person wanting to improve guesses correctly, did they actually learn anything? Can they use that next time? They definitely can if they get it wrong and have a wrong answer to start research with. Edit - I see that I misread your comment, please disregard this. I thought the quiz had don't know and the other options you specified.
- acveilleux 10y agoOr perhaps you're not a native english speaker?
- tedunangst 10y agoIndeed. It's not like the answers are unknowable.
- kmill 10y agoThe question is "what would the return value be," and without knowing which compiler is used you don't know what it would return. It doesn't make sense to say the program returns "undefined behavior" or "implementation-dependent." You might be taking issue with the question itself, but I think it's a valid question because C compilers tend to be lenient with what they compile.
- gkya 10y agoI can't know != I don't know
- amelius 10y agoYes, and "I can't know" is a stronger assertion than "I don't know". The former implies the latter. However, both are correct.
- gkya 10y agoThing is I can know if the necessary information is provided (i.e. CPU architecture, version of the standard). Portability is a feature of C, but C's portability is mostly syntactic and only partly semantic.
- jwdunne 10y agoBut if the necessary info isn't provided, you don't know because, as you say, you can't know. It's semantics. On many exams, "don't know" is a correct answer when you can't know because info is intentionally left out.
- gkya 10y agoI don't really want to be a pedant here, but in this case if the necessary information was provided, I had the knowledge to find a correct answer. This is different from the case where even if the information was provided I wouldn't be able to know because I don't have the necessary knowledge.
- anindha 10y agoI wasn't confused. The first one is pretty obvious it's unknown and "I don't know" is the closest answer.
- shp0ngle 10y agoIt's pretty clear it's tongue-in-cheek.
- cortesoft 10y agoThe purpose of this quiz is not to gauge the taker's knowledge of the subject, it is to make a point.
- cpkpad 10y agoIndeed. The quiz doesn't start with "What does the ANSI C standard guarantee about..." It says "So you think you know C." C is a cross-platform assembly language. I use it when I need to code to the metal. I know exactly how it will behave in most of those scenarios. I understand, in abstract, I might be on an EBCDIC system, and things will be different. But that's not the reality of C. C isn't just a formal specification. I spent a while on 1, thinking about how my compiler would handle that. 2 I was 90% confident about. 3 and 4 I was 100% confident about.
- deleted 10y ago[deleted]
- rkangel 10y ago> C isn't just a formal specification No, C IS just a formal specification. What you are talking about is C on your particular compiler on your particular platform. If you are writing C code just to be used for that scenario then you can use all of the implementation understanding you want. If, however, you want to write C that will have consistent behaviour across multiple compilers and multiple platforms, then you need to limit yourself to the behaviours that the standard guarantees. Otherwise the compiler behaviour may change and your program behaviour will change. Even between different versions of the same compiler implementation defined behaviour can change (although assumptions about sizes probably won't).
- yoklov 10y agoA lot of the implementation defined behavior can be ensured with static assertions (either via new-fangled C11 _Static_assert or via the old fashioned negative length array hack), particularly WRT sizes.
- rkangel 10y agoAbsolutely, and that's a big step forward to writing code that will silently do bad things on a different platform. I use that technique on my current project to assert a load of things that I know are true. It doesn't get you as far as the ideal goal which is to write code that will silently work on another platform. Static asserts mean that you then have to go and write more code when they happen.