0

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.

Steve
  • 551
  • 2
  • 8
  • 18

2 Answers2

2

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

A quick shell script

find . -name "*.cpp" -exec echo "" >> {} \;
Martin York
  • 257,169
  • 86
  • 333
  • 562
  • You sure that >> doesn't have to be escaped? – asveikau Dec 17 '09 at 05:03
  • 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 Dec 17 '09 at 05:13
  • 1
    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 Dec 17 '09 at 14:49
1

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 
alanc
  • 4,102
  • 21
  • 24
jon hanson
  • 8,722
  • 2
  • 37
  • 61
  • -erroff=E_NEWLINE_NOT_LAST didn't work for me, but -erroff=nonewline did. thanks joh. really appreciated. – Steve Dec 17 '09 at 23:16