-18

Today I asked this question, which I was expecting an answer explaining why, possibly involving analysis of the generated assembly.

It didn't took more than a few minutes before a C gold tag badge holder closed my question as a duplicate of another poor one that doesn't answer mine in any way, except "it's undefined behavior".

This incident reminds me of previous times when I was CV-ing poor C/C++ questions. Such ones also usually didn't get any comment explaining why except "it's undefined behavior" before getting closed as dupes of other well-referenced questions.

Is Stack Overflow too pedantic about that? In many cases, it'd be more helpful to tell the user how exactly the code behaved that way, in addition to just a single statement "it's undefined behavior".

error: undefined reference to "behavior" (.text+stackoverflow)
5
  • 5
    Undefined behavior is rarely reproducible unless a very specific compiler version is mentioned and asked about. Thus I close vote such questions as "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." Apr 13, 2019 at 9:05
  • 17
    It's a language issue, not a Stack Overflow issue. Because the C language has a concept of "undefined behavior", it means that analyzing the various ways in which that undefined behavior can manifest is neither interesting nor instructive. It also falls outside the scope of Stack Overflow, which is to cover practical programming problems. Once you know that your code is wrong, then you should fix it, not ponder on all the various ways that it can go wrong. Apr 13, 2019 at 9:06
  • 4
    If a user is that bothered by their own UB, they can step through their own code that was generated by their own compiler, linked by their linker, loaded by their own OS, located by their own memory manager into their own RAM. Why would anyone else waste their time on trying to reproduce/explain/whatever someone else's UB? Apr 13, 2019 at 9:33
  • It’s ok to say, this is UB, full stop. And this is the right attitude if one is targeting multiple platforms/compilers. On the other hand, stopping there means often missed opportunity to learn. Given that there are so many views, what is useful, one should not be surprised that some of such question get closed and some answered. One can argue for both sides.
    – ead
    Apr 13, 2019 at 10:49
  • @CodyGray Well, occasionally there are popular "not practical" questions... AFAIK there's no close reason for "this question is not practical" -- not that I encourage them.
    – user202729
    Apr 14, 2019 at 7:10

1 Answer 1

23

The problem ultimately comes down to this: we don't know what you want unless you tell us.

You say that you expected "an answer explaining why, possibly involving analysis of the generated assembly". But you didn't ask for that. You never said anything that suggested that you were aware that the code you wrote is dysfunctional and therefore that you shouldn't expect it to behave similarly on different platforms. You didn't say "this is UB, but I'm curious as to why this particular UB elicited this particular response".

You just posted the question as though you were wholly and completely ignorant of the fact that your code is broken. And thus, people answered you as such.

If you want to investigate the low-level specifics of how a particular manifestation of undefined behavior works in a specific context, that is... fine I guess. But if that's what you're asking for, you need to be very specific that this is what you want. We need to know that you are aware that this code is bad and should not be written or relied upon.

This is mainly to prevent people who don't know better from thinking that this is supposed to work, that this is some kind of defined behavior that ought to accomplish something. If you're interested in exercising your curiosity about ABIs, specific compiler implementations, and undefined behavior, that's fine. But it needs to be done in a question that makes it clear that you are deliberately exploring this domain.


In many cases, it'd be more helpful to tell the user how exactly the code behaved that way

I disagree. Most users who ask a question that looks like yours do not need to know about these things, and should not know about these things at this point in their understanding of the language. People who screw up printf formatting are almost always new users. What they need to know is "you put the values in the wrong place, and it looked the same because you screwed up".

Giving them a 2-page long screed about assembly, ABI, and so forth that explains why that specific thing happened in one case and happened differently on a different compiler is not what most such users need to see. That may be what you're asking for, but that's why you need to be specific that you are asking for it.

You must log in to answer this question.

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