473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Warning: no newline at end of file

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

Jan 12 '06 #1
8 31636
Ian
su*********@gmail.com wrote:
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
Jan 12 '06 #2
<su*********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
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.
Jan 12 '06 #3
no, ,just vc do not issue this warning.

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

Jan 12 '06 #4
"baibaichen" <ba********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
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.
Jan 12 '06 #5
Jim Langston wrote:
"baibaichen" <ba********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
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.


http://gcc.gnu.org/ml/gcc/2001-07/msg01120.html

Arne

--
[--- PGP key FD05BED7 --- http://www.root42.de/ ---]
Jan 12 '06 #6
"Arne Schmitz" <ar**********@gmx.net> wrote in message
news:42*************@news.dfncis.de...
Jim Langston wrote:
"baibaichen" <ba********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
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.


http://gcc.gnu.org/ml/gcc/2001-07/msg01120.html

Arne


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.
Jan 12 '06 #7
Jim Langston wrote:
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.


*Your* compiler handles it.
Quoting http://www.cse.unsw.edu.au/~patrykz/...fc/tdfc9.html:

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

Arne

--
[--- PGP key FD05BED7 --- http://www.root42.de/ ---]
Jan 12 '06 #8
Arne Schmitz wrote:
Jim Langston wrote:
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.


*Your* compiler handles it.
Quoting http://www.cse.unsw.edu.au/~patrykz/...fc/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.
Jan 12 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Teddy | last post by:
Hello all I've just upgraded my g++ compiler to 3.3.3 on Cygwin. But there is always a annoying warnig message "no new line at end of file" no matter what code you writes. How to get rid of...
12
by: B Thomas | last post by:
Hi, I was reading O'Reilly's "Practical C programming" book and it warns against the use of scanf, suggesting to avoid using it completely . Instead it recomends to use using fgets and sscanf....
27
by: MK | last post by:
I am a newbie. Please help. The following warning is issued by gcc-3.2.2 compiler (pc Linux): ================================================================== read_raw_data.c:51: warning:...
2
by: padam.singh | last post by:
Hi, I enable All Warnings during compiling my programs. What is the significance of this warning: warning: no newline at end of file I use gcc to compile, but wonder why it needs a newline...
29
by: runningdog | last post by:
Hi, I would like to be able to embed a newline in a text string. Is there any convienent notation to do this TIA Steve
55
by: Sameer | last post by:
Hi, when i compile my C programs (even 2 line progs) give the warning, no new line at end of file. What does this mean ? -Regards, Sameer
7
by: Alex Nordhus | last post by:
I am looking for a way to strip the blank line and the empty newline at the end of the text file. I can get the blank lines removed from the file but it always leaves the end line (which is blank)...
11
by: rossum | last post by:
I want to declare a const multi-line string inside a method, and I am having some problems using Environment.NewLine. I started out with: class foo { public void PrintStuff() { const...
16
by: pereges | last post by:
I'm getting a warning on my linux gcc compiler: /tmp/ccXgHa9s.o(.text+0x48): In function `main': : warning: the `gets' function is dangerous and should not be used. And here's where I used...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.