Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old January 12th, 2006, 07:35 AM
surendran.d@gmail.com
Guest
 
Posts: n/a
Default 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

  #2  
Old January 12th, 2006, 08:15 AM
Ian
Guest
 
Posts: n/a
Default Re: Warning: no newline at end of file

surendran.d@gmail.com wrote:[color=blue]
> 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.
>[/color]
gcc expects a new line at the end of a file, give it one.

Ian
  #3  
Old January 12th, 2006, 10:15 AM
Jim Langston
Guest
 
Posts: n/a
Default Re: Warning: no newline at end of file

<surendran.d@gmail.com> wrote in message
news:1137050637.235554.276780@g47g2000cwa.googlegr oups.com...[color=blue]
> 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
>[/color]

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


  #4  
Old January 12th, 2006, 11:45 AM
baibaichen
Guest
 
Posts: n/a
Default Re: Warning: no newline at end of file

no, ,just vc do not issue this warning.

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

  #5  
Old January 12th, 2006, 12:35 PM
Jim Langston
Guest
 
Posts: n/a
Default Re: Warning: no newline at end of file

"baibaichen" <baibaichen@gmail.com> wrote in message
news:1137065883.302429.99910@g14g2000cwa.googlegro ups.com...[color=blue]
> no, ,just vc do not issue this warning.
>
> however, there should be a potential problem if we miss newline...[/color]

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


  #6  
Old January 12th, 2006, 12:55 PM
Arne Schmitz
Guest
 
Posts: n/a
Default Re: Warning: no newline at end of file

Jim Langston wrote:
[color=blue]
> "baibaichen" <baibaichen@gmail.com> wrote in message
> news:1137065883.302429.99910@g14g2000cwa.googlegro ups.com...[color=green]
>> no, ,just vc do not issue this warning.
>>
>> however, there should be a potential problem if we miss newline...[/color]
>
> I don't see how there could possibly be a problem if VC handles it.[/color]

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

Arne

--
[--- PGP key FD05BED7 --- http://www.root42.de/ ---]
  #7  
Old January 12th, 2006, 02:15 PM
Jim Langston
Guest
 
Posts: n/a
Default Re: Warning: no newline at end of file

"Arne Schmitz" <arne.schmitz@gmx.net> wrote in message
news:42n11qF1j6mdlU1@news.dfncis.de...[color=blue]
> Jim Langston wrote:
>[color=green]
>> "baibaichen" <baibaichen@gmail.com> wrote in message
>> news:1137065883.302429.99910@g14g2000cwa.googlegro ups.com...[color=darkred]
>>> no, ,just vc do not issue this warning.
>>>
>>> however, there should be a potential problem if we miss newline...[/color]
>>
>> I don't see how there could possibly be a problem if VC handles it.[/color]
>
> http://gcc.gnu.org/ml/gcc/2001-07/msg01120.html
>
> Arne[/color]

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.


  #8  
Old January 12th, 2006, 02:25 PM
Arne Schmitz
Guest
 
Posts: n/a
Default Re: Warning: no newline at end of file

Jim Langston wrote:
[color=blue]
> 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.[/color]

*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/ ---]
  #9  
Old January 12th, 2006, 05:35 PM
red floyd
Guest
 
Posts: n/a
Default Re: Warning: no newline at end of file

Arne Schmitz wrote:[color=blue]
> Jim Langston wrote:
>[color=green]
>> 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.[/color]
>
> *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
>[/color]

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.
 

Bookmarks

Thread Tools

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles