Closed nintendoeats closed 10 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).
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):
??/
, 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 withx = 1;
would have been treated as part of a multiline comment rather than as executable code. Therefore the output would have been0
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.
I agree that we should expand the explanation. @knatten take a look please
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?
The question has now been retracted: https://cppquiz.org/quiz/question/147
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?