1

Recently I asked How does Operator Precedence affect Order of evaluation?.

It came to me as a surprise that it was not very well received, because as far as I am concerned it follows the guidelines of how to ask a good question.

I made sure that the question is not a duplicate, not off-topic, has a fitting title, has correct grammar and spelling, uses code samples wherever needed, states credible sources (Cppreference.com and Stack Overflow answers) wherever needed, includes all relevant tags, is not vague and states my question clearly.

Yet I neither got any answers, upvotes or suggestions on how to improve my question.

How can I improve my question so that I get an answer?

15
  • 4
    It's not surprising that was poorly received. It's not a practical programming question, which are the type that we prefer. No C programmer writes code like that, unless it's for an IOCCC entry. It certainly falls into the category of "not interesting", and unless a question is interesting and/or relevant, people are not likely to read a long one. Also, how are you so certain it's not a duplicate? A duplicate was proposed in a comment hours ago, and it seems to me to be a duplicate of several FAQ on operator precedence, order of evaluation, and sequencing.
    – Cody Gray Mod
    Sep 10, 2022 at 10:29
  • 1
    The code snippit was only of demonstrative purposes. As for the duplicate, I it indeed is about the same topic, I but it doesn't answer my specific questions.
    – Aiko
    Sep 10, 2022 at 10:50
  • 10
    First of all: shorten it. Sep 10, 2022 at 10:53
  • 3
    Additionally, there are plenty of dupes for your question.
    – Jason
    Sep 10, 2022 at 11:40
  • 5
    "As for the duplicate, I it indeed is about the same topic, I but it doesn't answer my specific questions." What are your specific questions? That linked duplicate does seem to cover your question title and your highlighted points (1-4). Note: I am not an SME and might be wrong Sep 10, 2022 at 11:42
  • 4
    Re "has correct grammar and spelling": Not quite... Casually, I found 7 spelling mistakes, just letting the spell checker in Firefox do its thing for the detection (only "unsequenced" was a false positive) and Edit Overflow, in collaboration with a macro keyboard, did the grunt work of the corrections. There were also "its" vs. "it's" and run-on sentences. Sep 10, 2022 at 17:28
  • 1
    cont ' - Though the average question quality in this regard on Stack Overflow is so low that this question was already in the top 1%. So it probably didn't matter too much for the short-term outcome. Sep 10, 2022 at 17:41
  • 1
    The title and first paragraph are too unspecific. They make it look like a vague beginner question that has been asked thousands of times. Given the length, I assume it isn't. This should be reflected in a more specific title. And it should be possible for the reader to get the gist of the question by only reading the first paragraph. A device could be the inverted pyramid. Sep 10, 2022 at 17:47
  • "I want to ask about" is superfluous. That is implied by posting on Stack Overflow and/or by converting the statement into a question. Sep 10, 2022 at 17:55
  • 1
    I agree with @user3840170, the primary issue is it's way too long. I won't read a question that long unless I find it really interesting, and many other SO answerers are the same. Sep 10, 2022 at 19:32
  • 2
    Whenever I see a question about code that could be trivially cleaned/simplified by the use of extra temporary vars and extra brackets, my heart sinks:(( ...I mean, there's always at least one on the first page: stackoverflow.com/q/73672645/758133 Sep 11, 2022 at 3:29
  • 3
    @CodyGray The issue is certainly practical programming because it is about the meaning of program text. It happens to be about the general case, not just the example, but even if it weren't, it is reasonable to ask about applying the general rules to a particular case. But it is a poor question for other reasons. You are a moderator, please talk to other moderators about this.
    – philipxy
    Sep 11, 2022 at 9:30
  • 1
    What do you want me to talk to other moderators about, @philipxy? A question doesn't become practical just because "it's about the meaning of program text". If it's not a real problem that a programmer would ever encounter, then it's not something that one would expect to be well-received here, even though it's technically on-topic.
    – Cody Gray Mod
    Sep 11, 2022 at 12:11
  • 2
    I am not going to repeat myself, I was clear. I told you what to check with them on & you yourself think you know what I meant because you just defended yourself. But there is no reason to give your reasoning again. You seem to be saying, you don't need to check on that because your reasoning is sound & here is your reasoning again, but I just told you why your reasoning is not sound & to please check with other mods, there is no reason to give your reasoning again. You seem to be saying "What do you want me to talk to other moderators about" to communicate incredulity that I could disagree.
    – philipxy
    Sep 11, 2022 at 13:20
  • 4
    Oh, you want me to check with them because you think I'm wrong? I see. Yeah, I already asked for someone to help translate your comment because it honestly wasn't clear to me what you wanted me to check with the other moderators. I was just trying to respond to the multiple points you had raised in your comment. @philipxy
    – Cody Gray Mod
    Sep 11, 2022 at 13:25

2 Answers 2

4

The question is absurdly long for what it's trying to ask. I tried (without submitting) to cut out noise (keep in mind that this is not a discussion forum) and redundancy, and I still found that there was a multiple-paragraph exposition of a mental model, just to get to an actual question of "is this mental model correct?"

The thing is, the concept isn't remotely that complicated.

The question title already succinctly states the underlying question: "How does Operator Precedence affect Order of evaluation?" As asked, this is fairly vacuous. In the example code int i=++a*b+c/d/e, the steps are - as you've already identified:

  • ++a is evaluated, incrementing a and using the new value.
  • a * b and c / d / e are evaluated (each is a term in the arithmetic expression), in an undefined order.
  • The two terms are added.
  • The result is assigned to i.

"Operator precedence" is the name of the rule that tells you that a * b and c / d / e have to be evaluated before the +, rather than (if + had the same precedence as * and /) evaluating everything left to right or (if the precedence relationship were inverted) evaluating b + c before all of the multiplications and divisions.

It has nothing to do with optimizations. Optimization might become possible due to the fact that the compiler can choose whether to compute a * b or c / d / e first. But both "operator precedence" and "order of operation" are about what things do have to happen before whichever other things. It's because the compiler is allowed to ignore side effects when choosing an order for those two steps, that undefined behaviour occurs. (That is the importance of sequence points.)

I guess I accidentally answered the entire question - as far as I could make any sense out of it - rather than figuring out how to make a proper question out of it. It was a lot easier that way. Oops.

6
  • You don't touch on the order of evaluation part. For example for: a * b, a and b would also be evaluated (consider they are function calls having side effects) and this won't be left-to-right and either of them might be evaluated first. Sep 11, 2022 at 10:35
  • ??? The order of the bullet points in the bulleted list is the order of evaluation. a and b are not function calls here; they are not placeholders for sub-expressions, but literal variables. Do you see function-call syntax? I do not. I explicitly explain that the order is not specified between a * b and c / d / e, which is analogous to the function calls in your hypothetical. Sep 11, 2022 at 10:38
  • 2
    That's the part where the OP isn't very clear on their question they use variable references in their example but they put forth that evaluating that reference itself might have side effects as that reference could easily be a function call instead. You can see that on this paragraph: "In the expression ((c/d)/e) if c,d or e have side effects (for example, if they were functions modifying global values) then it does actually make a difference in which order they are evaluated even if they are evaluated before the value computation of the result of the operator." Sep 11, 2022 at 10:41
  • 2
    ... Oh. There was so much text that I didn't even spot that part. Given that OP's example already included a sub-expression with side effects (++a), it seems rather redundant. Sep 11, 2022 at 10:45
  • "undefined behaviour occurs" "because" the standard says it does. Whatever you're trying to say by "It's because the compiler is allowed to ignore side effects when choosing an order for those two steps, that undefined behaviour occurs.", you're not saying it. I guess you're trying to talk about behaviour that happens when executing code with undefined behaviour. But then you're abusing the term "undefined behaviour".
    – philipxy
    Sep 11, 2022 at 16:40
  • Yeah, I fumbled that, which is especially irritating because of OP's apparent need for precision. Not sure what to do about it, either. It's been a very long time since I used C or C++. Sep 12, 2022 at 8:22
3

C++ questions with the are a bit semi-stable. You either get a ton of upvotes or a ton of downvotes. The quality of the question is rarely an indicator.

I asked a similar question before which got a +13/-2 score and had tons of comments pointing out that it's a clear duplicate. That could have easily been +2/-13.

Working with the C++ standard is very difficult. I think people are just very annoyed from beginners that don't really understand the topic well enough to see that their question has already been answered elsewhere.

If it didn't have a bounty on it it probably would have been closed as a duplicate immediately and would most likely have a score of 0.

You must log in to answer this question.

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