Coder Social home page Coder Social logo

Confused by Question #147 about cppquiz HOT 5 CLOSED

nintendoeats avatar nintendoeats commented on September 7, 2024
Confused by Question #147

from cppquiz.

Comments (5)

knatten avatar knatten commented on September 7, 2024 2

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?

from cppquiz.

nintendoeats avatar nintendoeats commented on September 7, 2024 1

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.

from cppquiz.

tocic avatar tocic commented on September 7, 2024

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).

from cppquiz.

tocic avatar tocic commented on September 7, 2024

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

from cppquiz.

knatten avatar knatten commented on September 7, 2024

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

from cppquiz.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.