Live data from Hacker News

So you think you know C? (2016)

wordsandbuttons.online

241–250 of 344 posts

Re: So you think you know C? (2016)

#242
There is a difference between "I don't know" and "undefined behaviour".

I know that most of this stuff is undefined according to the spec. But I (might) also know what my particular GCC version does in these cases.

What I know for sure, that those programs do output something, and it's not "I don't know" (the string) ; )

What I don't know, is what level of sophistication the author assumes.

Re: So you think you know C? (2016)

#243

Earlier quoted context omitted.

I couldn't agree more. After spending many years working with LLVM, which is at its heart a C compiler, and understanding why it has to do the sometimes-terrifying things it has to do to get C to run well, I've become very paranoid when writing C or C++. My C/C++ code is as boring as possible. (In fact I try to avoid writing C or C++ whenever possible these days; undefined behavior in the language is too pernicious a…

What would we write drivers in then if C was obsoleted?

Zig

Re: So you think you know C? (2016)

#244

Earlier quoted context omitted.

To me "I don't know" is a very apt choice. It makes the point clear that indeed reading the code does not allow you to know the result, which is quite a pitfall. In your comment you are jumping from "I don't know", which is the first step, to wanting to explain why.

But the point is that I do know what that will print on my computer(s), with my compiler(s), on my architecture(s). "I don't know" is too generic a statement.

Even on a given CPU with a given compiler you usually do not know until you've tried.

This is an article about the C language and the starting point with all the examples is that you do not know for a fact what the result will be.

Re: So you think you know C? (2016)

#245

Earlier quoted context omitted.

Though different people consider different things simple. To one a loop is fine, to another a map is a better choice.

map/filter/reduce is simpler, but it takes some getting used to. Loops have worn a deep rut in my brain.

As someone who was introduced to programming via map/filter/reduce, for loops are incredibly more complicated.

I don’t think I’ve ever written one correctly on first try.

Re: So you think you know C? (2016)

#246

Earlier quoted context omitted.

To me "I don't know" is a very apt choice. It makes the point clear that indeed reading the code does not allow you to know the result, which is quite a pitfall. In your comment you are jumping from "I don't know", which is the first step, to wanting to explain why.

But the point is that I do know what that will print on my computer(s), with my compiler(s), on my architecture(s). "I don't know" is too generic a statement.

On your computer yes, but the question specifically doesn't tell you what computer and compiler are used. So thus you can't know what the number is.

Re: So you think you know C? (2016)

#247

Earlier quoted context omitted.

"I cant know" is a subset of "I dont know" "I dont know" was absolutely the correct answer.

Except from the perspective of a pragmatics linguistic analysis, "I don't know" has a social context of "There's an answer, and I don't know it." In this case, a non-C programmer should answer "I don't know" to all of them. A person with a passing familiarity should answer similarly. A seasoned pro would be forced to answer the same. Making it a rather useless tool for distinguishing people who think they know C but…

>which is supposed to be the point of the exercise.

I don't think that assumption is justified. Someone could say the point of the exercise is to illustrate that C is confusing.

Re: So you think you know C? (2016)

#248

Earlier quoted context omitted.

Each of the questions has exactly one answer that is correct regardless of version and platform.

It would be correct to answer that I don't have enough information to choose an option. It's incorrect to answer that I don't know.

No, but there are (at least) two interpretations of ”I don’t know.” It’s a nice little exercise in epistemology.

Re: So you think you know C? (2016)

#249
post #21

I failed on one, number 4. I bravely assumed 16 bit integers cannot exist. Can anyone name a concrete platform/compiler where int is/was 16 bit. Or is this just a theoretical option left open by the spec?

x86 for one, up until 32-bit was introduced with the 80386.

Re: So you think you know C? (2016)

#250
post #30

There 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…

To me "I don't know" is a very apt choice. It makes the point clear that indeed reading the code does not allow you to know the result, which is quite a pitfall. In your comment you are jumping from "I don't know", which is the first step, to wanting to explain why.

There were multiple questions where I would have answered "It's undefined" or "It's implementation defined", but those weren't options. It's not that I don't know the answer; I know the answer ("it's implementation defined according to the spec, but on essentially every relevant platform, the result will be X"), but the "it's implementation defined" part of my answer isn't an option, so the only possible answer becomes "on essentially every relevant platform, the answer is X".

Using "I don't know" as a substitute for "I know that the standard clearly covers this, and it says that the result depends on the implementation" does seem to be designed to piss off people who know C. If they really wanted to get the point across that you don't know what is and isn't implementation defined or undefined, they shouldn't be using vague questions to mislead people; they should just plainly ask questions which people don't know the answer to.

I hate this kind of questioning where you 100% know the subject matter the quiz is asking about, but the question and possible choices is so vague you have to try to interpret what you suspect the person who wrote the quiz wants the answer to be. I once had an exam which was full of that kind of multiple choice question, and guessed the exam author's intentions wrong on most of them.

Post reply on HN