You can do whatever you want—it is your answer. By the same token, the people who read your answer can also vote on it however they want—it's their vote.
So the whole spirit of this Meta question is a little bit specious to me. Are you honestly trying to figure out if your answer is good/useful? If so, I think you can let the community answer that one. Not the Meta community, of course, but the c community. They have spoken by voting on your answer, and they will continue to speak. At this point, it is fairly clear that they consider it to be not an especially useful answer.
The only other option is that you're running to Meta, hoping to get some sympathy for your answer being downvoted. Sorry, I have no sympathy for that. I wouldn't be particularly sympathetic even if you had posted the best answer of the day, because votes are individual decisions and I'm not here to second-guess the people who cast them. But I'm especially unsympathetic in this case, because I agree that this is a bad answer.
Quoting myself:
What in the question gives you the impression that the asker knows this is undefined behavior? He says he is trying to predict the output, and doesn't understand why it isn't working the expected way. An answer that fails to mention this is undefined behavior is a bad answer because it is incomplete. You are not going to learn much of anything useful by "deliberately doing undefined things." … An answer about the C language that ignores the language standard is a bad answer.
You indicate, both in the comments and in an update to the question, your belief that the question makes it "reasonably clear" the asker understands what he is doing is undefined behavior. Two points:
Even if that were true, answers are intended for more than just the person who asks the question. Their arguably most important target audience are the millions of users who arrive at Stack Overflow looking for an answer to a similar question. Even if this guy happens to be a genius on the language committee who wrote the spec for printf
and contributed its implementation to GCC, the odds are that people who arrive at this question in the future will not be as knowledgeable. Therefore, if your answer fails to cover one of the most important pieces of information pertinent to the question, it is not a good answer and not likely to be useful.
If you're right about this, the asker may even accept your answer, while the community simultaneously downvotes it. It is a bad answer to the question in general, but a helpful answer to the person who asked the question. Again, as I mentioned at the top, it is your answer to post. Leave it, improve it, delete it, whatever you want to do with it. There is no "general consensus" to be established here, outside of what the C community has already spoken clearly on.
I very much disagree that the question provides any indication that the person knows this is undefined behavior. Your reading is far too generous. He says that "the output seems random on my computer...I try to predict the output by...". Statements like this are generally not made by people who understand that undefined behavior is and what it means. He goes on to say that "I expected its print some value near &a"—wait, what? Isn't that just saying that he expected the behavior to be defined in a certain way, but found out that it is not defined?
It also seems quite unlikely to me that a person who knows this is undefined behavior would even be asking this question. Good programmers don't write code that exhibits undefined behavior and then try to figure out why it is behaving in that way. Upon learning that their code exhibits undefined behavior, they fix their code, rewriting it so that it is in compliance with the language standard. An answer that glosses over this is not only wrong—it is not even wrong.
It's hard to settle this debate about the author's intent, of course, since neither of us are inside his head. But even if we were to get confirmation from zhiwenf himself that he understands what undefined behavior is, it wouldn't make your answer useful in the larger sense, because future Googlers wouldn't learn anything about the undefined behavior either by reading the question or by reading your answer.
dlsym()
either as casting avoid*
to avoid(*)()
is a constraint fault? So we are not allowed to answer questions about gcc extensions either? About the inter-operating between C and C++? You are being hypocritical in my opinion. It is nowhere said that OP wants to do this in production code. It is pretty clear that OPs code is an experiment. Is it verboten to write intentionally bad/undefined code to study what it does?dlsym
: The point you have to make there is that while the C standard does not handle that, the additional standards the implementations in question follow (name them) define that behavior.libffi
or a compiler, and then dissecting this particular case. I only have power over whatever I vote, which answers to give bounties, and which answers to link forward, but if "internet points" are of any importance to you, you'd notice that the community very well stated why they were downvoting your answer whilst upvoting the other, general (but perhaps not so thorough) answer.