LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-27-2009, 07:48 AM   #1
Cyhaxor
Member
 
Registered: Nov 2004
Location: UK
Distribution: Fedora 12
Posts: 129

Rep: Reputation: 15
Smile C++: no new line at the end of file


Hello,

I'm playing around with C++ and I discovered that if you save a source file and you don't put an empty line after the last '}' (you don't press enter) the compiler compiles your source but with a warning message. Why is that happening? Is there anything that can goes wrong if I don't put an end line? That is not a problem for me but I'm just asking to satisfy my curiosity and learn something..

Thanks in advance
 
Old 01-27-2009, 08:59 AM   #2
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
C++ Standard [2.1.1.2] declares:

... 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
before any such splicing takes place, the behavior is undefined.

( google ... no new line at the end of file ... )
....
 
Old 01-27-2009, 12:47 PM   #3
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
You should try using a different text editor with your source file. Every decent editor nowadays should end every line with an end of line character (sounds kind of stupid, doesn't it?), including the last line of the file.
 
Old 01-27-2009, 01:18 PM   #4
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Quote:
Every decent editor nowadays should end every line with an end of line character (sounds kind of stupid, doesn't it?), including the last line of the file.
Yeah, I hate that feature.
 
Old 01-27-2009, 04:11 PM   #5
Cyhaxor
Member
 
Registered: Nov 2004
Location: UK
Distribution: Fedora 12
Posts: 129

Original Poster
Rep: Reputation: 15
I'm using kwrite. I don't know if kwrite is considered to be an old editor but I'm covered with knudfl's answer Thanks.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
No new line at end of file? What does this mean? BajaNick Programming 12 05-19-2014 08:39 PM
C: fread to read a file line by line until the end Blue_muppet Programming 2 09-19-2008 09:42 AM
Warning: no new line at the end of file kerenLinuxForum Programming 7 09-08-2008 08:15 AM
warning: no new line at end of file? Four Programming 5 01-07-2006 12:21 AM
adding new line at end of file airikah Programming 3 11-08-2003 04:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration