• How good is your C++ knowledge?

    From Tim Rentsch@21:1/5 to All on Tue Jan 14 09:31:45 2025
    Check this out -- https://cppquiz.org

    (My own results on the handful of questions I tried
    were less than stellar.)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Ahlstrom@21:1/5 to David Brown on Tue Jan 14 15:11:33 2025
    David Brown wrote this post while blinking in Morse code:

    On 14/01/2025 18:31, Tim Rentsch wrote:
    Check this out -- https://cppquiz.org

    (My own results on the handful of questions I tried
    were less than stellar.)

    177 questions? That's a /lot/ of questions to wade through. Could you
    tell us at least if you think some of the questions are interesting,
    rather than either quite basic or quite unrealistic?

    The very first one was some printf() calls that would cause a compilation error. The answer box was a tiny thing, making one things that there would be /some/ output.

    That one seemed like a C question, really.

    --
    Contains no artificial colors or ingredients.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Brown@21:1/5 to Tim Rentsch on Tue Jan 14 20:25:25 2025
    On 14/01/2025 18:31, Tim Rentsch wrote:
    Check this out -- https://cppquiz.org

    (My own results on the handful of questions I tried
    were less than stellar.)

    177 questions? That's a /lot/ of questions to wade through. Could you
    tell us at least if you think some of the questions are interesting,
    rather than either quite basic or quite unrealistic?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Phillip@21:1/5 to Tim Rentsch on Tue Jan 14 15:57:43 2025
    On 1/14/25 12:31 PM, Tim Rentsch wrote:
    Check this out -- https://cppquiz.org

    (My own results on the handful of questions I tried
    were less than stellar.)

    Believe it or not I've seen a lot of businesses that use this web site
    (or others like it) as part of their interview process. So it's a pretty
    big deal sometimes.

    --
    Phillip
    ----------
    - Adam: Is a void really a void if it returns?
    - Jack: No, it's just nullspace at that point.
    ----------

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paavo Helde@21:1/5 to Lynn McGuire on Wed Jan 15 17:51:00 2025
    On 15.01.2025 08:13, Lynn McGuire wrote:
    On 1/14/2025 11:31 AM, Tim Rentsch wrote:
    Check this out -- https://cppquiz.org

    (My own results on the handful of questions I tried
    were less than stellar.)

    I got the first question on the first try.  I got the second question on
    the third try.  I bounced on the third question.

    These are not trivial questions.  There are serious logic questions in there.

    Indeed. Almost each question has some gotcha included.

    Not sure how much this would help for interviewing newcomers,
    willingness to learn and ability to get things done would be far more
    important than knowledge of obscure C++ gotchas.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Muttley@DastardlyHQ.org@21:1/5 to All on Wed Jan 15 16:37:59 2025
    On Wed, 15 Jan 2025 17:51:00 +0200
    Paavo Helde <eesnimi@osa.pri.ee> wibbled:
    On 15.01.2025 08:13, Lynn McGuire wrote:
    On 1/14/2025 11:31 AM, Tim Rentsch wrote:
    Check this out -- https://cppquiz.org

    (My own results on the handful of questions I tried
    were less than stellar.)

    I got the first question on the first try.  I got the second question on
    the third try.  I bounced on the third question.

    These are not trivial questions.  There are serious logic questions in
    there.

    Indeed. Almost each question has some gotcha included.

    Not sure how much this would help for interviewing newcomers,
    willingness to learn and ability to get things done would be far more >important than knowledge of obscure C++ gotchas.

    Unfortunately "spot whats wrong with this code" or "what will this code do" have long been staples of interviews, at least here in the UK almost
    invariably involving IME convoluted multiple inheritence. Its a lot easier
    for lazy interviewers to just go through a checklist of answers than
    ask someone to write some code and have to figure out what they did. Unless
    you solely want to hire people to bug fix wierd edge cases then its far more useful IMO to see how they problem solve and what sort of code they write.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to Lynn McGuire on Sat Jan 18 07:55:50 2025
    Lynn McGuire <lynnmcguire5@gmail.com> writes:

    On 1/14/2025 11:31 AM, Tim Rentsch wrote:

    Check this out -- https://cppquiz.org

    (My own results on the handful of questions I tried
    were less than stellar.)

    I got the first question on the first try. I got the second question
    on the third try. I bounced on the third question.

    These are not trivial questions. There are serious logic questions in
    there.

    The level of difficulty covers a big range. I don't know that any
    of the questions are completely trivial; they all seem to have at
    least some little twist to them. But some are completely out of the
    park, as far as my own C++ knowledge goes. On the plus side, I did
    learn some things in trying some of the mid-range questions.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rosario19@21:1/5 to Tim Rentsch on Mon Jan 20 13:17:19 2025
    On Tue, 14 Jan 2025 09:31:45 -0800, Tim Rentsch wrote:

    Check this out -- https://cppquiz.org


    one big subset of C++: the art for make difficult what is always been
    easy

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Muttley@DastardlyHQ.org@21:1/5 to All on Mon Jan 20 16:12:56 2025
    On Mon, 20 Jan 2025 13:17:19 +0100
    Rosario19 <Ros@invalid.invalid> wibbled:
    On Tue, 14 Jan 2025 09:31:45 -0800, Tim Rentsch wrote:

    Check this out -- https://cppquiz.org


    one big subset of C++: the art for make difficult what is always been
    easy

    I hate these types of tests. They don't prove anything other than if you
    give enough plausible answers you can confuse people. The kind of tests where people are asked to write some code to do a specific task is a far better measure of someones capability that spotting stupid syntax errors that would
    be caught during compilation anyway and semantic errors that would be evident on the first run.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Vir Campestris@21:1/5 to Lynn McGuire on Wed Jan 22 11:23:43 2025
    On 15/01/2025 06:13, Lynn McGuire wrote:

    I got the first question on the first try.  I got the second question on
    the third try.  I bounced on the third question.

    These are not trivial questions.  There are serious logic questions in there.

    The second question I got was to compare typeid(x)==typeid(y). I worked
    out whether they matched correctly. But it wrote the answer using stream
    IO to cout, and I assumed that when you write a bool it would write true
    or false. I gave up in the end, and asked for the answer. Which was
    either 0 or 1 (I won't say which in case someone else wants to do the question).

    So all my knowledge of the language and the way classes work was as
    nothing given that I almost never use stream IO for anything other than
    play programs. (OTOH I'm retired now, and only write play programs...)

    I suspect a real person scoring it would have realised my error!

    Andy

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paavo Helde@21:1/5 to Vir Campestris on Wed Jan 22 16:30:01 2025
    On 22.01.2025 13:23, Vir Campestris wrote:
    On 15/01/2025 06:13, Lynn McGuire wrote:

    I got the first question on the first try.  I got the second question
    on the third try.  I bounced on the third question.

    These are not trivial questions.  There are serious logic questions in
    there.

    The second question I got was to compare typeid(x)==typeid(y). I worked
    out whether they matched correctly. But it wrote the answer using stream
    IO to cout, and I assumed that when you write a bool it would write true
    or false. I gave up in the end, and asked for the answer. Which was
    either 0 or 1 (I won't say which in case someone else wants to do the question).

    Right. It appears this behavior can be modified via the std::boolalpha
    and std::noboolalpha manipulators.

    And the printed names can be changed from 'true' and 'false' to
    something else by defining a custom locale and overriding do_truename()
    and do_falsename() virtual functions.

    Considering that C++ is meant for creating programs for all people, not
    just English speakers, and thus the names can be redefined, outputting
    '0' and '1' by default actually makes some sense.

    Anyway, I guess this all this just proves there is no lack of material
    for adding yet more obscure C++ questions to that quiz ;-)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Andrey Tarasevich@21:1/5 to Tim Rentsch on Sat Feb 8 21:22:34 2025
    On Tue 1/14/2025 9:31 AM, Tim Rentsch wrote:
    Check this out -- https://cppquiz.org

    I came across a rather interesting question.

    Remember back in the day we had that issue with a pair of `>>` being interpreted as a single token? So, when closing multiple levels of
    nested triangular brackets we had to separate them by spaces `> >`.
    Eventually this issue has been resolved at grammatical level, and there
    was no need to be concerned about it anymore.

    In modern C++ (apparently, since C++11) we now have another issue of
    somewhat similar structure: a pair of consecutive `[` brackets. In
    "classic" C++ we had no contexts in which consecutive `[` brackets would legally appear. But now have at least two such contexts: one is using a
    lambda to access an array element

    int a[10]{};
    int x = a[[]{ return 0; }()];

    Another is attributes (which grammatically begin with two `[`). Two
    consecutive `[` are required to begin an attribute, meaning that the
    above code sample is ill-formed.

    What came as a bit of surprise to me is that inserting an extra space
    between the `[` apparently does not resolve the situation. I.e. this variant

    int x = a[ []{ return 0; }() ];

    is still ill-formed.

    --
    Best regards,
    Andrey

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From James Kuyper@21:1/5 to Andrey Tarasevich on Sun Feb 9 16:17:13 2025
    On 2/9/25 00:22, Andrey Tarasevich wrote:
    ...
    Remember back in the day we had that issue with a pair of `>>` being interpreted as a single token? So, when closing multiple levels of
    nested triangular brackets we had to separate them by spaces `> >`. Eventually this issue has been resolved at grammatical level, and there
    was no need to be concerned about it anymore.

    They didn't correct that by changing the grammar. They simply added a
    rule that
    "When parsing a template-argument-list, ... the first non-nested >> is
    treated as two consecutive but distinct > tokens, the first of which is
    taken as the end of the template-argument-list and completes the
    template-id." (13.3p4).

    ...
    Another is attributes (which grammatically begin with two `[`). Two consecutive `[` are required to begin an attribute, meaning that the
    above code sample is ill-formed.

    What came as a bit of surprise to me is that inserting an extra space
    between the `[` apparently does not resolve the situation. I.e. this variant

    int x = a[ []{ return 0; }() ];

    is still ill-formed.

    That's because, as you your self mention, the attribute syntax
    "grammatically begin with two '['". Since those are two separate tokens, (unlike ">>", which is a single token) they can be separated by an
    arbitrarily long string of white-space characters which get removed
    during translation phase 7.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Muffley@PillowHQ.org@21:1/5 to All on Mon Feb 10 08:26:43 2025
    On Sun, 9 Feb 2025 16:17:13 -0500
    James Kuyper <jameskuyper@alumni.caltech.edu> wibbled:
    On 2/9/25 00:22, Andrey Tarasevich wrote:
    ....
    Remember back in the day we had that issue with a pair of `>>` being
    interpreted as a single token? So, when closing multiple levels of
    nested triangular brackets we had to separate them by spaces `> >`.
    Eventually this issue has been resolved at grammatical level, and there
    was no need to be concerned about it anymore.

    They didn't correct that by changing the grammar. They simply added a
    rule that
    "When parsing a template-argument-list, ... the first non-nested >> is >treated as two consecutive but distinct > tokens, the first of which is
    taken as the end of the template-argument-list and completes the >template-id." (13.3p4).

    Which is another nice example of how the C++ syntax was never really thought through properly but is just one hack on top of another.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Muffley@PillowHQ.org@21:1/5 to All on Mon Feb 10 10:00:53 2025
    On Mon, 10 Feb 2025 10:46:17 +0100
    David Brown <david.brown@hesbynett.no> wibbled:
    On 10/02/2025 09:26, Muffley@PillowHQ.org wrote:
    On Sun, 9 Feb 2025 16:17:13 -0500
    James Kuyper <jameskuyper@alumni.caltech.edu> wibbled:
    On 2/9/25 00:22, Andrey Tarasevich wrote:
    ....
    Remember back in the day we had that issue with a pair of `>>` being
    interpreted as a single token? So, when closing multiple levels of
    nested triangular brackets we had to separate them by spaces `> >`.
    Eventually this issue has been resolved at grammatical level, and there >>>> was no need to be concerned about it anymore.

    They didn't correct that by changing the grammar. They simply added a
    rule that
    "When parsing a template-argument-list, ... the first non-nested >> is
    treated as two consecutive but distinct > tokens, the first of which is
    taken as the end of the template-argument-list and completes the
    template-id." (13.3p4).

    Which is another nice example of how the C++ syntax was never really thought >> through properly but is just one hack on top of another.


    It /was/ thought through properly when C++ was new. But the language

    I'm not aware of what was in the language when it was still C-with-classes,
    but operator overloading AFAIK is, if not an original feature then certainly
    a very old one, and the postfix syntax is a fugly hack.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Brown@21:1/5 to Muffley@PillowHQ.org on Mon Feb 10 10:46:17 2025
    On 10/02/2025 09:26, Muffley@PillowHQ.org wrote:
    On Sun, 9 Feb 2025 16:17:13 -0500
    James Kuyper <jameskuyper@alumni.caltech.edu> wibbled:
    On 2/9/25 00:22, Andrey Tarasevich wrote:
    ....
    Remember back in the day we had that issue with a pair of `>>` being
    interpreted as a single token? So, when closing multiple levels of
    nested triangular brackets we had to separate them by spaces `> >`.
    Eventually this issue has been resolved at grammatical level, and there
    was no need to be concerned about it anymore.

    They didn't correct that by changing the grammar. They simply added a
    rule that
    "When parsing a template-argument-list, ... the first non-nested >> is
    treated as two consecutive but distinct > tokens, the first of which is
    taken as the end of the template-argument-list and completes the
    template-id." (13.3p4).

    Which is another nice example of how the C++ syntax was never really thought through properly but is just one hack on top of another.


    It /was/ thought through properly when C++ was new. But the language
    has had a great deal of new features since it first started seeing
    real-world usage, and all new features have to fit compatibility with
    existing code. That applies to all languages that see significant
    development over time.

    Of course if you wanted to make a /new/ language with most of the
    features C++ currently has, you'd have a grammar that differed
    significantly from C++ and which did not suffer from these kinds of
    issues. That's what projects like "Cpp2" are hoping to achieve. (And
    if they catch on, they'll suffer from the same problem a few decades
    down the line.)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paavo Helde@21:1/5 to Muffley@PillowHQ.org on Mon Feb 10 15:52:28 2025
    On 10.02.2025 12:00, Muffley@PillowHQ.org wrote:
    On Mon, 10 Feb 2025 10:46:17 +0100
    David Brown <david.brown@hesbynett.no> wibbled:
    On 10/02/2025 09:26, Muffley@PillowHQ.org wrote:
    On Sun, 9 Feb 2025 16:17:13 -0500
    James Kuyper <jameskuyper@alumni.caltech.edu> wibbled:
    On 2/9/25 00:22, Andrey Tarasevich wrote:
    ....
    Remember back in the day we had that issue with a pair of `>>` being >>>>> interpreted as a single token? So, when closing multiple levels of
    nested triangular brackets we had to separate them by spaces `> >`.
    Eventually this issue has been resolved at grammatical level, and there >>>>> was no need to be concerned about it anymore.

    They didn't correct that by changing the grammar. They simply added a
    rule that
    "When parsing a template-argument-list, ... the first non-nested >> is >>>> treated as two consecutive but distinct > tokens, the first of which is >>>> taken as the end of the template-argument-list and completes the
    template-id." (13.3p4).

    Which is another nice example of how the C++ syntax was never really thought
    through properly but is just one hack on top of another.


    It /was/ thought through properly when C++ was new. But the language

    I'm not aware of what was in the language when it was still C-with-classes, but operator overloading AFAIK is, if not an original feature then certainly a very old one, and the postfix syntax is a fugly hack.

    Operator overloading predates C++ and is already present in C. In C, the expression `x >> 1` works both for unsigned int, unsigned long, and
    unsigned long long, and produces different opcodes and different result
    types for them. That's clear overloading.

    Parsing of characters `>>` is done by the C or C++ lexer. The C lexer
    needs to look ahead (though one character only) for deciding how to
    interpret the first '>'. The C++ lexer needs to look backwards for
    deciding how to interpret the second '>'. Not so different IMO.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Muffley@PillowHQ.org@21:1/5 to All on Mon Feb 10 14:56:29 2025
    On Mon, 10 Feb 2025 15:52:28 +0200
    Paavo Helde <eesnimi@osa.pri.ee> wibbled:
    On 10.02.2025 12:00, Muffley@PillowHQ.org wrote:
    I'm not aware of what was in the language when it was still C-with-classes, >> but operator overloading AFAIK is, if not an original feature then certainly >> a very old one, and the postfix syntax is a fugly hack.

    Operator overloading predates C++ and is already present in C. In C, the >expression `x >> 1` works both for unsigned int, unsigned long, and
    unsigned long long, and produces different opcodes and different result
    types for them. That's clear overloading.

    Don't be willfully dumb, you know what I mean. Eg:

    myclass &operator++ (int)
    {
    :
    }

    The 'int' is a ridiculous hack to signify postfix. There are far neater ways
    it could have been done, eg a post_operator keyword or something similar.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Muffley@PillowHQ.org@21:1/5 to All on Mon Feb 10 15:53:14 2025
    On Mon, 10 Feb 2025 17:18:52 +0200
    Paavo Helde <eesnimi@osa.pri.ee> wibbled:
    On 10.02.2025 16:56, Muffley@PillowHQ.org wrote:
    Don't be willfully dumb, you know what I mean. Eg:

    myclass &operator++ (int)
    {
    :
    }

    The 'int' is a ridiculous hack to signify postfix. There are far neater ways >> it could have been done, eg a post_operator keyword or something similar.

    I see. I was indeed wondering what you mean by 'postfix', but the
    current thread is all about <<...>> and [[...]], so I was confused.

    It was simply an example of how C++ - apart from maybe in the beginning - has not really been designed but rather is a succession of bodges to get something to work on top of pre-existing syntax.

    OTOH, the `>>` misparse was indeed a nuisance in the past.

    And should never have happened because templates defs should never have used
    < and > in the first place especially given that << and >> had already been cretinously overloaded to use for streams instead of inventing a new operator for them. The '@' character for example is available on every computer keyboard and is still waiting to be used by C++ for something. No reason it couldn't have been used for template defs.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paavo Helde@21:1/5 to Muffley@PillowHQ.org on Mon Feb 10 17:18:52 2025
    On 10.02.2025 16:56, Muffley@PillowHQ.org wrote:
    On Mon, 10 Feb 2025 15:52:28 +0200
    Paavo Helde <eesnimi@osa.pri.ee> wibbled:
    On 10.02.2025 12:00, Muffley@PillowHQ.org wrote:
    I'm not aware of what was in the language when it was still C-with-classes, >>> but operator overloading AFAIK is, if not an original feature then certainly
    a very old one, and the postfix syntax is a fugly hack.

    Operator overloading predates C++ and is already present in C. In C, the
    expression `x >> 1` works both for unsigned int, unsigned long, and
    unsigned long long, and produces different opcodes and different result
    types for them. That's clear overloading.

    Don't be willfully dumb, you know what I mean. Eg:

    myclass &operator++ (int)
    {
    :
    }

    The 'int' is a ridiculous hack to signify postfix. There are far neater ways it could have been done, eg a post_operator keyword or something similar.

    I see. I was indeed wondering what you mean by 'postfix', but the
    current thread is all about <<...>> and [[...]], so I was confused.

    I rarely write my own iterator classes, so the weird syntax of postfix increment does not bother me so much. I have never used a lambda for
    indexing an array, so the '[[' issue has not bothered me either.

    OTOH, the `>>` misparse was indeed a nuisance in the past.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)