1

I have a line of C++ code:

cout << bool((x++) == (++x)) << x;  

I'm looking for deeper intuition as what is going on in this statement, but I'm not sure if Stack Overflow, or another Stack Exchange site, would be the place to ask this. If yes, I'll go ahead and post my question! If no, would anyone advise where I might ask this type of question?

15
  • What do you mean by "intuition"? Do you want someone to explain what it does? Or what sort of brain disease would cause someone to write something like that?
    – Becuzz
    Feb 5, 2016 at 16:40
  • I would also emphasize that it is not a "forum" and perhaps that will lead you to better understanding of the sites intent (and read the site usage documents) Feb 5, 2016 at 16:40
  • 5
    The word "forum" has more than one meaning. It may well be used appropriately here (not as in "online forum" but as in "venue")
    – Pekka
    Feb 5, 2016 at 16:41
  • my guess would be deeper understanding, and i'm not sure if that would be well received as a question or in chat for the C++ community here. It would be fine in javascript chat as long as you didn't make a habit of it, but the two communities are different and I don't take part in the C++ community.
    – Kevin B
    Feb 5, 2016 at 16:41
  • Deeper understanding would be correct. The above code snippet is an just for an example case, and I'd like to understand why it outputs what it does. Edit: But in the above example, I'm not sure how to word it as a specific question... which is why I don't want to spam it on the question board without asking some of your opinions. :)
    – Nanomurf
    Feb 5, 2016 at 16:42
  • 1
    As Pekka pointed out, it may be taken poorly if done wrong. This is really just to reiterate and impress upon you how important this part is: Explain what of the snippet you're asking about you already understand! Be sure to also clearly explain, to the best of your abilities, what confuses you about the rest of the snippet, or at least point out what little bit of it you don't understand or need clarified. But most important is to make sure you clearly explain what you already understand, to truly narrow down the post.
    – Kendra
    Feb 5, 2016 at 16:45
  • Thank you all for the feedback. I appreciate it. I'll give it a shot.
    – Nanomurf
    Feb 5, 2016 at 16:47
  • 1
    Why would you ever write code like this? Feb 5, 2016 at 16:59
  • 2
    No. Negative. Not today or romorrow recurring. Non. Nein. Please. Do. Not. Post. Code. Like. That. Ever. Feb 5, 2016 at 17:00
  • 4
    Garbage code like the example above pours into the C and C++ tags with monotonous and sickening regularity. Nobody outside an insane asylum or a college, (obvious joke would not be appreciated), would emit characters strung together in that way. All such code is homework, of the worst kind, it is not wanted. Feb 5, 2016 at 17:02
  • 2
    'Deeper understanding' means "my homework question asks for the output of the code with 'Explain your reasoning' " Feb 5, 2016 at 17:08
  • I am surprised at the hostility of this place :/ I'm just asking a question.
    – Nanomurf
    Feb 5, 2016 at 17:14
  • @Nanomurf - you picked a REALLY bad example of code:( Note that the 'hostility' is directed at your example, not yourself personally. Also, please note that 'hostile' is an adjective that is nearly always applied to people, ('showing or feeling opposition or dislike; unfriendly), and is likely to cause personal offense. Feb 5, 2016 at 17:31
  • These comments make me wonder if codereview.stackexchange.com might be the place with a question of "How can I make this code more understandable and maintainable" or some such... Feb 5, 2016 at 17:47
  • 2
    Don't EVER ask a question like this in the C++ tag. You will be murdered. I mean literally. They will track you down and kill you.
    – user1228
    Feb 5, 2016 at 19:11

2 Answers 2

5

Edit: Some experts in the tag in question have weighed in; for this specific case, it's probably best to heed their advice. I myself have no experience in the tag.

Back in the day, this question would have worked great on Stack Overflow, no problem and no questions asked (ha ha).

It may no longer work that way, though. The rules have evolved, or devolved, depending on who you ask. At any rate they are more strict and narrow than they used to be and anything that looks like a stupid/lazy question runs the risk of getting closed. That's sometimes unfair, but then there's 10,000+ questions pouring in every day, so maybe it's inevitable.

I'd say it's still worth giving a try, if you can handle the risk of getting negative feedback.

Success will greatly depend on how you word the question. Whatever you do, don't just post the line and ask "what is going on here?"

Make sure you add some context, and what you managed to understand so far.

8
  • Try? I, for one, would downvote immediate and close as dup. Feb 5, 2016 at 17:05
  • @Martin I don't really know much C++ so I can't say anything about the quality of that particular question, nor whether it has any dupes (which I gather from your comment it has). That obviously changes the equation, might be worth an answer of its own
    – Pekka
    Feb 5, 2016 at 17:06
  • 3
    @Pekka웃 well, hmm, how can I explain how bad it is without getting suspended again... . . it's sorta like obfuscated brainfuck. Feb 5, 2016 at 17:14
  • 2
    It's like "CAUTION: This sealed partial for toxic material repositories is attached to an epitaxially activated gazenta." vs the "Storage" sign on the door in the chem lab. One seems easier to understand. Just because you can...well you know. Feb 5, 2016 at 18:16
  • You've sent this poor man to his death.
    – user1228
    Feb 5, 2016 at 19:12
  • 1
    @Will if he survives and comes your way, give him a place to sleep and something to eat on your popcorn farm, will you?
    – Pekka
    Feb 5, 2016 at 19:20
  • 1
    Are you insane? With the C++ mafia out for his blood? No way. No way in hell.
    – user1228
    Feb 5, 2016 at 19:36
  • 1
    @Will fair point.
    – Pekka
    Feb 5, 2016 at 19:36
6

Maybe you just picked a particularly poor example for your question, but code such as you posted is, to say the least, unwelcome for the following reasons:

  1. It looks crazy and, indeed, it is.

  2. Any such code could easily be expanded over multiple lines to make both its intent, and operation, clear.

  3. Anyone suffering from complex expressions (Boolean or otherwise), that either do not work, or cannot be quickly understood, should split up the expressions into multiple lines and use plenty of intermediate, temporary vars to make debugging easier. The compiler will create the same output code once optimization is turned up after testing/debugging. This is debugging 101, and anyone who posts here without following that procedure should stop writing code and retake their entire course.

  4. Anyone unlucky enough to happen upon such code while attempting to debug some obscure problem would go looking for a tall building to jump off.

  5. It's a terrible example to future users/visitors to SO.

  6. It's existence on SO says 'professional and enthusiast programmers are idiots'.

  7. All such codes are thought up by profs/TAs during Friday afternoon Tequila sessions.

So, no thanks.

0

Not the answer you're looking for? Browse other questions tagged .