knatten / cppquiz

Source for the http://cppquiz.org website (not the questions)
GNU General Public License v3.0
101 stars 14 forks source link

Confused by Question #147 #324

Closed nintendoeats closed 10 months ago

nintendoeats commented 11 months ago

What is going on here indeed! The only test seems to be whether we are brave enough to assume that the world is sane, and the code we are looking at is real. Glad to know that stuff in comments doesn't get compiled?

tocic commented 11 months ago

Please look at the compiler explorer link given in the answer. You can add the -trigraphs option to see the difference (it will compile, but the result will be different).

nintendoeats commented 11 months ago

That's neat, and I'm happy to know about it, but here's the thought process I went through (which I'd think is the same for most users):

  1. I really really hope that this is 1.
  2. But it couldn't possibly be 1. I mean, why would they ask?
  3. There's this unusual comment, but it's just a comment.
  4. Even the syntax highlighter agrees, that's just a comment
  5. Well I give up, I'm entering 1.
  6. image
  7. So I'm right that this is 1.
  8. And I'm right that that was just a comment.
  9. So what I have learned was that there used to be a trigraph called ??/, but I don't know what it does and it's not actually relevant to the question I just answered.

Can you see why, coming at it from that perspective, the question just comes across as very strange?

I think what it comes down to is, if you knew what this trigraph was and what it did then this question is about "did you know this was removed in C++17". But if you don't (which I think is pretty common, given that it was removed), the question is "can you read code", and the answer description says "there's also a thing here which does nothing and is ignored".

Perhaps the solution is to add something like this to the explanation:

Prior to C++17, the ??/ was parsed by the preprocessor as being equivalent to the character \. Thus, the next line with x = 1; would have been treated as part of a multiline comment rather than as executable code. Therefore the output would have been 0 in older versions of the standard. You can reenable this behavior in GCC using the -trigraphs option, or by specifying -std=c++14.

In addition, this is marked as level 3 difficulty. Makes it more confusing, since unless you know a piece of esotera this appears to be one of the most straightforward programs one could possibly write.

tocic commented 11 months ago

I agree that we should expand the explanation. @knatten take a look please

knatten commented 11 months ago

I suggest we simply un-publish this question. It was created pre-C++17 when trigraphs were still a thing. Then it got ported to C++17 with the rest of the questions on the site, but I think it should have been unpublished instead since it no longer makes much sense. Any objections?

knatten commented 10 months ago

The question has now been retracted: https://cppquiz.org/quiz/question/147