1

I saw this one and it kind of annoyed me: Disable warning messages in GCC through header files?

Any C programmer knows that you really should be using fgets() instead of gets() due to the bounds checking done by the former. That's fine, the manpage says it, and the system (and I think the compiler too) goes out of it's way to tell you this by forcing a warning message to appear when you launch any program using the older call.

However - the question in the linked topic is not "what function should I use". The question is not "what are best practices".

The question is, in it's simplest form, "How do I get rid of the warning message"? The poster even clarifies this:

I am wondering that there might be such possibilities by creating a header file for disabling some warnings . Or is there any option during compiling that can serve my purpose? Or may be there is a particular way of using gets() for this warning not to pop up?

They obviously want the warnings killed without changing the function they use.

Not one of the answers, massively upvoted even, on that page, actually answer the question. (The one that tries doesn't work, as admitted by its author)

  • Should these kinds of things be reported?

I'm all for educating someone on what best practices actually are, but telling someone "just do Y instead" doesn't address the letter or the spirit of the question. Best would be "You can disable the warnings by doing X; but the warning is there for a good reason, you should really do X instead"

More to the point:

  • Am I being a massive jerk for downvoting answers that take this route?
1

2 Answers 2

4

Should these kinds of things be reported?

Not sure how you want to "report" them or what you would expect to be done. If you mean by flagging them, no. If they are an answer, albeit maybe poor answers, then they shouldn't be flagged...downvote and/or comment as you wish. After all, that's why we have those mechanisms.

Am I being a massive jerk for downvoting answers that take this route?

I'm not a C developer but, if you feel they are "wrong" and/or not best practices, by all means...downvote each if you so desire. Again, you can also comment because maybe the person answering doesn't understand that it is bad.

This happens all of the time in with people doing network operations on the main thread. There are a lot of answers that say to use StrictMode but this is well pointed out in the docs that it should only be used for debugging. Myself, and many others, will downvote these types of answers each and every time and usually comment.

What you also could do is to leave your own answer stating how the OP's question can be answered then emphasize that it is not the best practice and show how it should be done. Just because they aren't asking for a different function, doesn't always mean they aren't open to using something else. Maybe they don't know any better.

10

Any C programmer knows that you really should be using fgets() instead of gets()

This one apparently didn't.

They obviously want the warnings killed without changing the function they use.

Nothing in the question specifies that they wanted to avoid changing the function, and their comment on the answer they accepted "Thanks Neil...fgets works fine. thanks a lot." seems to indicate they were open to doing so.


Asking how to disable warnings there is an XY problem. The asker has problem X, that they're receiving a warning about the gets function; and assumed that Y, "creating a header file for disabling some warnings" is a solution. So they've asked how to do Y.

Solving X, by instructing them how to use fgets, is the proper response. Which is likely why it's the accepted answer.


Should these kinds of things be reported?

No. Even if you don't like the answers none of the answers there meet criteria for any kind of reporting.

telling someone "just do Y instead" doesn't address the letter or the spirit of the question

It doesn't address the letter of the question, but it absolutely solves the problem which is the spirit of the question.

Am I being a massive jerk for downvoting answers that take this route?

If you hover over the downvote arrow it says "This answer is not useful." If you truly believe that those answers are not useful, then vote them down.

Personally I feel they're far more useful as they address the actual problem, rather than the problem of the attempted solution.

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