views:

153

answers:

2

I have ported a fair bit of code from Win to Solaris, one of the issues I have - I am getting a heaps of warnings:

Warning: Last line in file is not terminated with a newline.

I like warnings - but because of the sheer amount of those I am afraid I could miss more important one.

Which compiler (cc) option should I specify to silence it?

Thanks.

+2  A: 

Or you could add an empty line to the end of each file.

A quick shell script

find . -name "*.cpp" -exec echo "" >> {} \;
Martin York
You sure that >> doesn't have to be escaped?
asveikau
the original code is being maintained under Windows and I am not keen of modifying original source base or keeping Windows (without empty line at the EOF) and Solaris (with empty line at the EOF) code out of sync.
Steve
Steve: you could add the new line even for Windows, and enforce by coding standards that each file has a new line. This way you won't need to modify anything for your Solaris build.
MP24
+1  A: 

Although i think Martin's solution of fixing the original source files would be preferable, if you really want to disable the warnings then this page describes the -erroff flag which you can use to disable specific warnings. In your case add

-erroff=E_NEWLINE_NOT_LAST

to the CC command line to switch the newline warning off, e.g.:

# Display the warning and the warning tag name.
/opt/forte/sunstudio11_patch2/SUNWspro/bin/cc -errtags=yes test.c
"test.c", line 1: warning: newline not last character in file (E_NEWLINE_NOT_LAST)

# Disable the warning.
/opt/forte/sunstudio11_patch2/SUNWspro/bin/cc -erroff=E_NEWLINE_NOT_LAST test.c
jon hanson
-erroff=E_NEWLINE_NOT_LAST didn't work for me, but -erroff=nonewline did. thanks joh. really appreciated.
Steve