Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What flag silences GCC's warning about no newline at file-endings?

I just read this post about why new-line warnings exist, but to be honest my team has people working on several different platforms and with several different editors (everyone uses what bests suites them), so the warning has become ubiquitous, and since its not really a warning worth taking care of it's become noise and makes finding serious warnings a hassle.

Many times important warnings have gone unnoticed because, people got used to having a gazillion useless warnings pass by, so they obviously just stop looking at them carefully, and with reason IMHO. One could say in our case GCC is crying wolf too much for anyone to take it seriously anymore, which is a bad attitude but its just human nature.

Right now we compile with -Wall, because we want warnings, but is there a counter flag to avoid the new-line warnings?

Note: I Looked through the manual a bit but didn't find the answer in any place obvious so I gave up.

Note: In response to Robert Gamble's totally reasonable solution, our code is cross-platform and we have people and builds on Linux, Solaris and Windows, so the new-line... is not under consensus. And Somebody's compiler is always going to cry-wolf. Because there are over 40 developers, and other non programmer staff as well.

like image 434
Robert Gould Avatar asked Nov 12 '08 02:11

Robert Gould


People also ask

How do I fix warning no newline at end of file?

That's not an error. It's just a warning. Open the file in an editor, go to the last line of the file, and hit enter to add a blank line to the end of the file. Though, besides that, you should be using #include <iostream> instead of <iostream.

What does the werror flag do?

The "-Werror" compiler flag treats all warnings as build errors. By promoting all warnings to errors, it enforces the developers to ensure such build warnings that may otherwise go unnoticed or only loosely concerned about by developers to now treat it with priority given that it will interrupt the build process.

Which GCC flag is used to enable all compiler warnings?

gcc -Wall enables all compiler's warning messages. This option should always be used, in order to generate better code.


1 Answers

Assuming you use some kind of source control system, you could add a pre-commit hook that ensures that text files end with a proper newline. Furthermore, depending on which source control system you use, you could add a pre-commit hook that actually fixes the line ending if it's not present.

like image 192
Greg Hewgill Avatar answered Sep 21 '22 02:09

Greg Hewgill