-4

When we are working on a big project of C or CPP, we are getting some warning. Therefore, we try to remove that warning because when we see compiler warnings that they make us feel dirty. When we search about specific warning, We get some solution to disable specific warnings.

So, I have a question, Is it really good idea to disable warning?

Jemes
  • 133
  • 4
  • 4
    No that's not a good idea, you should fix the warnings instead. They are there for a reason. – πάντα ῥεῖ Sep 12 '19 at 06:05
  • 1
    Short answer: no. Long answer: if the project is big and they aren't particularly serious warnings, you can disable at least on your local copy during compilation so that you don't regularly see them. I would still avoid committing changes which include disabling warnings, as it isn't a "fix" by any means. – Neil Sep 12 '19 at 06:22
  • 1
    See also [Compiler Warnings](https://softwareengineering.stackexchange.com/questions/17341/compiler-warnings) – Doc Brown Sep 12 '19 at 06:22
  • 1
    See also [Why should I always enable compiler warnings?](https://stackoverflow.com/questions/57842756/why-should-i-always-enable-compiler-warnings). – Theraot Sep 12 '19 at 06:34
  • there are cases where some warning could be ignored, you should always assume though that a warning is justified. The reason that it's a warning and not an error is that you are able to choose to ignore/ live with it. Some warnings are just bad luck and can't be avoided specially when working with 3rd party code. In General however set the compiler to treat warnings as errors and disable them in code using a reason – Walter Vehoeven Sep 12 '19 at 07:19
  • Disabling warnings is as good as hiding rotten food with a napkin – Sisir Sep 24 '19 at 08:47

1 Answers1

2

Errors are there to stop you doing things are not allowed like walking across Niagara Falls on foot (without any ropes or anything). It just can't be done, so the compiler say "No".

Warning are there for things that you might get away with, but you probably shouldn't try, like walking across Niagara Falls on a tightrope. Yes, some really, really skilful people can to this, but it's more likely that you're going to get wet (at best).

If anything, you should go the other way and promote Warnings into Errors and close the door on all these potential problems.

Failing that, if you really can't avoid a warning, then suppress that single instance of the warning: https://stackoverflow.com/questions/7159348/disable-single-warning-error

This is likely to work well, because it's more work for Developer(s).
They're more likely to take the "easy" option and fix the underlying problem instead of writing all those fiddly "extra" pragma statements. :-)

Don't be tempted to "forget" about warnings globally.

Phill W.
  • 11,891
  • 4
  • 21
  • 36