Live data from Hacker News

So you think you know C? (2016)

wordsandbuttons.online

11–20 of 344 posts

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

#16

Failed all of them. I totally agree with what the author is writing. Don’t presume anything but measure. I also tend to code in a way that it’s not necessary to know all the intricacies. Its not as clever as many like and often makes for longer code but is usually easier to read.

> Don’t presume anything but measure.

I think that's exactly the wrong takeaway here. Most of these have a well-defined result on a given platform (host + abi). You can measure that result. But it'll be different on a different platform. And the others don't have a well-defined result — a real-world compiler will produce a result, and you can measure that, but it might be different tomorrow. Unless you know the difference between platform-specific behavior and undefined behavior, you don't know which ones to avoid.

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

#17
I answered Idk to all. After the first two, the pattern became clear and I felt like if I wrote a compiler myself, the answers could be very different.

I've worked on 16 bit C code, 32 and now 64 bit code. So I knew that the behavior was implementation and optimization dependent. :)

Ignorance is bliss in C.

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

#18
post #15
post #6

OK you tricked me. But the test would have been better if the answer was "undefined behavior" instead of "I don't know".

Not all of them are undefined behavior

Sure, but "I don't know" makes it seem like you're just saying "pass", which, when you finish the test, is obviously not what it represents.

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

#19

My score is 3/5. One immediate redflag I have noticed is using "int", "char", "short" as if they have a definite size. They don't. C standard only guarantees a minimum size. For example, many PDPs are 36-bit. Assuming the size of a variable is a common practice nowadays, but at least one should use uint8_t, int32_t, etc. from stdint.h. But I was still tricked, it should be obvious in hindsight, 12 years of schooling…

In school, I was taught to choose the "best answer" on a test or quiz, and if you don't know something, choose the answer that looks right to you.

This test.. it reverses that entirely.

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

#20
post #11

At the end of the test, the author talks about automation programming for a nuclear power plant. I don’t think I could ever sleep the same at night after writing something like that.

Particularly writing it in C... It isn't a language well suited to be fully defined (see this very article for why), and no, Rust/Go aren't either. But Ada derivative or Haskell perhaps, there's some amazing tooling for safety critical systems and the languages themselves lend themselves to exposing side-effects.
Post reply on HN