Warning: no newline at end of file

S

surendran.d

hi,
I am using gcc 3.4.4 for c++, i am getting the following
warning if there is no new line at the EOF. Why this warning and i am
not getting the warning in vc++ compiler.

thanks,
suri
 
I

Ian

hi,
I am using gcc 3.4.4 for c++, i am getting the following
warning if there is no new line at the EOF. Why this warning and i am
not getting the warning in vc++ compiler.
gcc expects a new line at the end of a file, give it one.

Ian
 
J

Jim Langston

hi,
I am using gcc 3.4.4 for c++, i am getting the following
warning if there is no new line at the EOF. Why this warning and i am
not getting the warning in vc++ compiler.

thanks,
suri

Because gcc wants the newline and vc++ doesn't care.
 
B

baibaichen

no, ,just vc do not issue this warning.

however, there should be a potential problem if we miss newline...
 
J

Jim Langston

baibaichen said:
no, ,just vc do not issue this warning.

however, there should be a potential problem if we miss newline...

I don't see how there could possibly be a problem if VC handles it.
 
J

Jim Langston

Arne Schmitz said:

I just tested that in msvc++ .net 2003 and it compiles without problem.

File iostreamtest.h:
#include <iostream>
(no newline at end)

File stringtest.h:
#include <string>
(no newline at end)

File main.cpp:
#include "iostreamtest.h"
#include "stringtest.h"
int main()
{
std::string test = "Hello";
std::cout << test;
std::string Wait;
std::cin >> Wait;
}

Compiles and outputs Hello

Again, the compiler handles that. It probably just includes an extra
newline for include files.

So, since the compiler handles there not being no newlines at the end of a
file, it doesn't seem to be an issue so doesn't need a warning.
 
R

red floyd

Arne said:
*Your* compiler handles it.
Quoting http://www.cse.unsw.edu.au/~patrykz/TenDRA/tdfc/tdfc9.html:

"The ISO C standard, section 5.1.1.2, states that source files must end with
new lines."

Arne

ISO C++ Standard.

2.1/1.2 "If a source file that is not empty does not end in a new-line
character, or ends in a new-line character immediately preceded by a
backslash character, the behavior is undefined".

Ergo, both compilers are performing within the spec. You could get a
working program. You could get a warning. You could get an error.
Your program could compile to a virus that would wipe out the Internet
as we know it. It's UB.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top