5

I've just found this question: invalid conversion in C++. It is about a compilation error when using pointers to functions. It may not be self evident why the OP wrote this code, but the question contains:

  • the line that causes a compilation error (and enough context around it to understand that the error does not come from a previous line)
  • the full declaration of the struct containing the pointer to function
  • the exact error message

Despite this, the question soon got 2 down votes and one close vote for not containing an MCVE.

I admit that this usage of pointers is not common in C++ (at least for me) and I really had to read the question 3 times to fully understand it. But it was not because of the way it was written, simply that I had never encountered this kind of error before.

I know that we want to avoid poor questions in Stack Overflow, but this one already contained all that was necessary to understand the problem and the problem was not that trivial.

Maybe it lacks some context that was later added in a comment: that the OP got into this problem because they were porting working C code to C++.

So my question is: how could this question be written to be well received on Stack Overflow, or if it is the kind of question that we do not want, what are the reasons?

BTW: I posted an answer that was immediately accepted, so OP provided feedback on their question.

5
  • 4
    Asking a [c] question and tagging it [c++] is never appreciated. Cats and dogs. May 11, 2017 at 13:48
  • The only thing one could add would be the definition of SHA1_Init although it is completely clear from the error message what it is. It might get downvoted because the coding style is terrible for modern c++, but I also don't see any reason for closing the question.
    – BDL
    May 11, 2017 at 13:49
  • 1
    @HansPassant: It IS a C++ question. The question is: How can this C code be ported to C++.
    – BDL
    May 11, 2017 at 13:50
  • @HansPassant: OP specifically said he tried to use static_cast so it is clear he was using C++ (even if the code has a visible C origin) May 11, 2017 at 13:54
  • It is just an explanation. Having to very often wrestle through the noise myself (I answer questions about C++ language extensions) I neither endorse nor appreciate it. May 11, 2017 at 14:10

3 Answers 3

1

"Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example."

So, here's a checklist:

  • specific problem/error
  • shortest code necessary to reproduce
  • desired behaviour

The question at hand does include the code necessary to reproduce the problem, as well as a specific problem, but it fails at explaning (or even giving a hint at) the desired behaviour.

It also fails horribly at explaining how the OP stumbled upon this error, especially the fact that the OP is actually working with C-code, trying to export it to C++ for further usage.

Last but not least: Users that read the question & the tags may choose to downvote simply because it looks like very, very bad (because unsafe and prone to fail due to misuse) C++-code, which it isn't, but due to the tags & the missing explanation, that's an easy conclusion to make.


Concluding what I've said above, the question fails to explain what the desired behaviour is, and thus was downvoted. In its initial form it is unclear, hard to understand, and a prime-example for "Guessing"-questions, as well as potentially confusing readers due to not having a decent explanation and the C++-tag.

1
  • 1
    Thank you, that's a nice analysis... May 13, 2017 at 20:44
0

The question demonstrates inability to read error message, inability to read documentation and in general smells like an XY-problem by using pointers to implement something that looks like a class. And includes more code than needed for MCVE.

What could be done better:

  • adding explanation why pure C code is tagged C++ from the comment like "compiled C library with C++ to check correctness" would solve a lot of C/C++ and WTF you are doing that concerns
  • Real MCVE (including method signature that caused error). Note that code in the post is enough to show the problem, but not narrowing it down adds more reasons to downvote.
  • Showing code for actual attempts as well as trying all *_cast operators (reading about static_cast could give even more hints that those two pointers are not compatible in addition to error message).
  • Showing understanding of the problem and actually asking "why pointers to f(Type* p) and f(void* p) are not compatible in C++ while ok in C and how to fix it" or something similarly specific. In current state post looks like thousands of other "here is a compiler error. Fix it" questions.

I personally think lack of reasoning why question was even asked is the main factor for downvotes.

2
  • It is not exactly a X-Y problem, because here the goal is to quickly port C code to C++. But I think that you (and HansPassant) are right: showing C code in a C++ tagged question is not well received by C++ community... Because tons of question are much worse than this one IMHO, and are neither closed nor downvoted! May 11, 2017 at 15:56
  • 1
    @SergeBallesta if you look at the question (ignoring comments) there is absolutely no indication that this is C to C++ porting effort. Question reads as "I have this low level pointer code in C++ and it fails" - without explanation why it feels there are much better ways to achieve whatever goal with classes. I think you've read question differently than many other users - editing question to clarify (or even just editing in OP's comments) is reasonably fine. May 11, 2017 at 16:37
-2

This is mainly based on other answers here and from comments on this question and the original one.

IMHO the problem is not really the way the question is written. Ok, it does not really include a MCVE, but all the important information is present and many worse questions are neither downvoted nor closed.

But it is indeed a X-Y problem, even if I did not realize it at first sight. The problem of the question is that OP tries to compile C code as C++. In addition, it did not initially contained a context explaining that it was a C to C++ port attempt. But even with that context (or maybe because of it...) it is clearly X-Y, because porting C to C++ should not be done by simply compiling initial C code as C++, but should involve rewriting high level parts in modern C++, and eventually leaving lower level parts in C code. This is necessary to be able to make use of the C++ possibilities in terms of type safety, and end with easier to maintain code.

I have edited my original answer with that and left a comment on the question itself. But I still feel bad that none of the downvoters or close-voters have taken time to explain that in a comment. Maybe they only had a feeling of it, and did not clearly realize what was really bad in the question, but only that something smelled...

You must log in to answer this question.

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