Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C / C++ compiler warnings: do you clean up all your code to remove them or leave them in?

I've worked on many projects where I've been given code by others to update. More often than not I compile it and get about 1,000+ compiler warnings. When I see compiler warnings they make me feel dirty, so my first task is to clean up the code and remove them all. Typically I find about a dozen problems like uninitialized variables such.

I don't understand why people leave them in and don't have perfectly clean compiles with no warnings. Am I missing something? Is there any valid reason to just leave them? Any horror stories to share?

like image 722
KPexEA Avatar asked Oct 08 '08 17:10

KPexEA


People also ask

How do I remove compiler warnings?

To turn off the warning for a specific line of code, use the warning pragma, #pragma warning(suppress : 4996) .

Do compiler warnings matter?

They are not errors from the viewpoint of a programming language, but they may be software bugs. However, many compilers can be customized so that their warnings don't stop the compilation process. Warnings must not be ignored. You'd better fix every possible error before starting software testing.

How do you treat all warnings as errors in GCC?

You can make all warnings being treated as such using -Wno-error. You can make specific warnings being treated as such by using -Wno-error=<warning name> where <warning name> is the name of the warning you don't want treated as an error. If you want to entirely disable all warnings, use -w (not recommended).


2 Answers

I would clean up any warning. Even the ones that you know are harmless (if such a thing exists) will give a bad impression of you to whoever will compile the code.

It one of the "smelly" signs I would look for if I had to work on someone else code.

If not real errors or potential future issues, it would be a sign of sloppiness

like image 82
Remo.D Avatar answered Sep 23 '22 13:09

Remo.D


Clean 'em up, even if they don't indicate a real problem. Otherwise, if a warning that does indicate a real problem shows up, you won't see it through all the noise.

like image 30
Graeme Perrow Avatar answered Sep 23 '22 13:09

Graeme Perrow