5

I posted a question a few days ago that inspired some... well, "attack" seems a bit strong, but also somewhat appropriate.

When is it okay to do/use something that has unspecified behaviour?

I tried asking when it's ok in c++ to do or to use something that is somewhere in-between well-defined and undefined. There were comments saying "there is no such thing". I got down voted a lot.

There were votes to close on grounds of it being unclear what I was asking.

I clarified, and went into more detail with an example.

I asked it to be reopened, and it was.

I finally got an "answer" that listed the types of behaviour, and gave the term of "unspecified behaviour". I didn't know what it was called before then, so I edited my question again to reflect the proper terminology.

Now, finally it's been marked as a duplicate of a question asking what terms undefined, unspecified and well-defined mean. My question isn't about the definition, but rather it's about when is it ok/appropriate/best practice to use such behaviour. I also don't think this is unclear in any way, and that this question really irked some people.

Although I suspect that re-opening will open me up to more down-voting, I'm ok with that. I think this is a great question, and I wish others would bring in some discussion rather than attacking the question.

5
  • 3
    Without going to burn my fingers on anything in the c++ tag in general I'm not a great fan of questions that evolve due to answers being given. One user already deleted his answer because of the edits in your question...
    – rene
    Commented Jul 19, 2014 at 15:37
  • 1
    I was continuously asked for clarification, and I didn't know what else to do. Do you have a suggestion for how I could've handled it differently? Commented Jul 19, 2014 at 15:40
  • Thoughts on going back to an earlier revision? Commented Jul 19, 2014 at 15:41
  • No, I wouldn't do that...just keep it mind for your next question...
    – rene
    Commented Jul 19, 2014 at 15:42
  • I've decided to re-post as a new question. As I was editing it, I noticed that the question itself had changed. And so, I posted a new one. Hopefully this goes ok. Commented Jul 19, 2014 at 18:52

4 Answers 4

4

Only a bronze C++ holder here, but it was marked as a duplicate because once you know what the difference between the types of "bad behavior" specified by the standard, you trivially know when it's appropriate to use it: when you don't care about what's not specified.

Moreover, the question more or less misses the point: unspecified behavior is generally not used intentionally, unspecified behavior is employed in many parts of the standard because it allows compilers to more intelligently optimize. Most programs trigger unspecified behavior, just it's not a problem because we don't care about the gory details of compiler optimization and we get the right result out at the end. Which, while this question may or may not be a good excuse to clarify the situation, it's also a close reason: "Lacks minimal understanding."

IMO, this question was closed appropriately, either as a duplicate if the asker knew or as lacks minimal understanding if the asker did not.

12
  • No, you're wrong. I've seen a bunch of discussion along the lines of claiming there IS only undefined and well-defined behaviour. A good example of using unspecified behaviour intentionally would be multithreading. I understand this quite well, and I do want to get into those "gory details" - hence the question. Commented Jul 19, 2014 at 16:17
  • How am I wrong, exactly? Commented Jul 19, 2014 at 16:19
  • You claim I lack minimal understanding by asking this question, and that it's "trivially known" when it's appropriate to use it. Both of those are big claims. If you'd like to back them up, I'd like to see it. Commented Jul 19, 2014 at 16:21
  • I said, you lack minimal understanding only if you knew about unspecified behavior, but did not know that many things triggered it and it's not normally intentionally used. It's not intended as a dig or insult, and you seem to be aware of it, so... As far as the trivial part: If you have unspecified behavior, and you care about what's being specified, then it's inappropriate, if you do not, then it's appropriate, how can it get MORE trivial than that? Commented Jul 19, 2014 at 16:23
  • "I said, you lack minimal understanding only if you knew about unspecified behavior, but did not know that many things triggered it and it's not normally intentionally used" - and you implied that was the case by saying the question should be closed for that reason. Commented Jul 19, 2014 at 16:25
  • No, I said it should be closed EITHER as a duplicate OR as lacks minimal understanding, depending on what you know. Commented Jul 19, 2014 at 16:26
  • "As far as the trivial part: If you have unspecified behavior, and you care about what's being specified, then it's inappropriate, if you do not, then it's appropriate, how can it get MORE trivial than that?" - From what I'm seeing, this is not as obvious as it may seem. I think there are a lot of misconceptions about what category things fall into. Type punning with unions is a good example. Some claim it's undefined, and some say it's not undefined. People quote the standard on both sides, and no one can prove it either way. Commented Jul 19, 2014 at 16:27
  • Ok. breathes I think you and others are hearing me asking a question that is different than what I'm asking. I'll think about this some more. Commented Jul 19, 2014 at 16:28
  • Then you should restructure your question to be less broad and more specific, as type punning unions is not part of the question you asked. For clarity, the type punning question has been asked and answered, the reason why conflicting answers exist on that particular point is the standard changed between C99 and C11. See: stackoverflow.com/questions/11639947/… Commented Jul 19, 2014 at 16:33
  • I included type punning with unions as an example early on, but then it just started a flame war over whether or not it was undefined or not. I don't know the c standard, but the c++ standard seems less sure about type punning unions. stackoverflow.com/questions/11373203/… Commented Jul 19, 2014 at 16:36
  • The C++ standard builds off of the C standard. Anything in the C standard should be considered binding on the C++ standard unless overruled: see section 1.1 and 1.2. Checking your edits: at the time, your question only asked about "less than well-defined" behavior. So the close is even more appropriate imo. Commented Jul 19, 2014 at 16:47
  • There are a number of problems with the question as it is and as it was. Please collect your thoughts, come up with a specific question, and then ask it, provided it doesn't already have an ask/answer. Commented Jul 19, 2014 at 16:49
4

This question could be reopened, but you need to refine it a bit more first.

For starters, your follow-up question should be an entirely different question. Asking about the use-cases for unspecified is already pretty broad - throwing a tangential question into the mix makes it untenable.

Beyond that, make sure you've read the answers already written in response to the original question and highlight in your own the specific area where your concerns have not already been addressed. Emphasis on specific.

1
  • A reviewer can simply close it anyway and you're left without a manner of recourse. Commented Mar 22, 2021 at 21:27
3

I'm not familiar with the subject matter, but, after reading through your question and the purported duplicate, they do seem to be asking different questions, so I gave you an upvote because I feel like they are distinct enough and the question has some effort put into it (more than most, anyway).

However, it was marked as a duplicate by a gold badge holder: those with a gold badge in a tag have the power to mark any question as a duplicate instantly, which is reasonable since they have a score of 1000+ on the tag.

I can't really argue with someone who has a gold badge in a language I'm not familiar with, but your question, albeit a bit unclear, doesn't seem to be a duplicate to me.

However, it can sometimes be a problem when a question changes in response to the answers/comments it receives, which can render other answers useless and change the intent/context/properties of a question, which is never a good idea.

That could certainly have been the issue here, and it could have been what prompted the poor response.

4
  • The comments came out flying right away, it was very difficult to deal with. Is it ok to re-ask the question? I'm worried it'll get marked as a duplicate to this one. Commented Jul 19, 2014 at 15:46
  • @MGaz I'd read the answer that I pointed you to on your other question: don't re-ask a question just because another one got a poor response: it'll be marked as a duplicate if you're asking the same thing. Bringing it up on Meta was the right thing to do.
    – AstroCB
    Commented Jul 19, 2014 at 15:47
  • I guess it seems like a different situation when my question is wrongly closed. Commented Jul 19, 2014 at 15:49
  • 1
    @MGaz Don't weight this too heavily: I don't know C++ or anything about what you're asking. I'm just giving my opinion from what I read of those two posts as an outsider: you'll have to wait for someone else with more authority in this field to come along and give you their opinion.
    – AstroCB
    Commented Jul 19, 2014 at 15:50
2

Emphasis mine:

Now, finally it's been marked as a duplicate of a question asking what terms undefined, unspecified and well-defined mean. My question isn't about the definition, but rather it's about when is it ok/appropriate/best practice to use such behaviour.

I'm not very familiar with the subject matter, but questions asking about best practice are often closed as "primarily opinion-based". So it's possible that your question would get closed as such, if reopened.

However, again, I must state that I'm not very familiar with the subject to know for sure whether that is indeed the case.

1
  • I think the question itself is example of "unspecified". There are answers to the question that aren't opinion based, but not "just one", and it's not undefined either :D Commented Jul 19, 2014 at 17:37

You must log in to answer this question.

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