public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* What is the purpose of 'warning: no newline at end of file'?
@ 2005-07-07  3:34 Neo Anderson
  2005-07-07  3:40 ` Jonathan Turkanis
  0 siblings, 1 reply; 10+ messages in thread
From: Neo Anderson @ 2005-07-07  3:34 UTC (permalink / raw)
  To: gcc-help

I don't even think it's a problem. Why do I need (or better have) a line 
ending?


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: What is the purpose of 'warning: no newline at end of file'?
  2005-07-07  3:34 What is the purpose of 'warning: no newline at end of file'? Neo Anderson
@ 2005-07-07  3:40 ` Jonathan Turkanis
  2005-07-07  3:44   ` corey taylor
  2005-07-07  4:16   ` Neo Anderson
  0 siblings, 2 replies; 10+ messages in thread
From: Jonathan Turkanis @ 2005-07-07  3:40 UTC (permalink / raw)
  To: gcc-help

Neo Anderson wrote:
> I don't even think it's a problem. Why do I need (or better have) a line 
> ending?

The C++ standard says: If a source file that is not empty does not end in a 
newline character, or ends in a newline character immediately preceded by a 
backslash character, the behavior is undefined. (2.1/1)

Jonathan

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: What is the purpose of 'warning: no newline at end of file'?
  2005-07-07  3:40 ` Jonathan Turkanis
@ 2005-07-07  3:44   ` corey taylor
  2005-07-07  4:16   ` Neo Anderson
  1 sibling, 0 replies; 10+ messages in thread
From: corey taylor @ 2005-07-07  3:44 UTC (permalink / raw)
  To: Jonathan Turkanis; +Cc: gcc-help

And that undefined behavior is in the form of that warning you've
posted.  This simply lets you know what behavior the gcc developers
inserted.

You need the newline in order to have c++ standards behavior assumed
instead of gcc behavior -- it's a portability issue really.

corey

On 7/6/05, Jonathan Turkanis <technews@kangaroologic.com> wrote:
> Neo Anderson wrote:
> > I don't even think it's a problem. Why do I need (or better have) a line
> > ending?
> 
> The C++ standard says: If a source file that is not empty does not end in a
> newline character, or ends in a newline character immediately preceded by a
> backslash character, the behavior is undefined. (2.1/1)
> 
> Jonathan
> 
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: What is the purpose of 'warning: no newline at end of file'?
  2005-07-07  3:40 ` Jonathan Turkanis
  2005-07-07  3:44   ` corey taylor
@ 2005-07-07  4:16   ` Neo Anderson
  2005-07-07  4:32     ` Ian Lance Taylor
                       ` (2 more replies)
  1 sibling, 3 replies; 10+ messages in thread
From: Neo Anderson @ 2005-07-07  4:16 UTC (permalink / raw)
  To: gcc-help

So, what is the purpose of this warning? What possible 'damages' does this 
warning protect against?


And, what is the 'the behavior'?

----Original Message Follows----
From: Jonathan Turkanis <technews@kangaroologic.com>
To: gcc-help@gcc.gnu.org
Subject: Re: What is the purpose of 'warning: no newline at end of file'?
Date: Wed, 06 Jul 2005 21:41:20 -0600

Neo Anderson wrote:
>I don't even think it's a problem. Why do I need (or better have) a line 
>ending?

The C++ standard says: If a source file that is not empty does not end in a 
newline character, or ends in a newline character immediately preceded by a 
backslash character, the behavior is undefined. (2.1/1)

Jonathan


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: What is the purpose of 'warning: no newline at end of file'?
  2005-07-07  4:16   ` Neo Anderson
@ 2005-07-07  4:32     ` Ian Lance Taylor
  2005-07-07  4:39     ` Jonathan Turkanis
  2005-07-07 11:35     ` Eljay Love-Jensen
  2 siblings, 0 replies; 10+ messages in thread
From: Ian Lance Taylor @ 2005-07-07  4:32 UTC (permalink / raw)
  To: Neo Anderson; +Cc: gcc-help

"Neo Anderson" <neo_in_matrix@msn.com> writes:

> So, what is the purpose of this warning? What possible 'damages' does
> this warning protect against?

None.  Personally, I think the compiler should only issue this warning
with -pedantic.

> And, what is the 'the behavior'?

In this quote:

> > The C++ standard says: If a source file that is not empty does not end
> > in a newline character, or ends in a newline character immediately
> > preceded by a backslash character, the behavior is undefined. (2.1/1)

"the behavior" refers to the behavior of the compiler.  It means that
the standard does not specify how the compiler must behave when it
sees a non-empty file which does not end with a newline.

Ian

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: What is the purpose of 'warning: no newline at end of file'?
  2005-07-07  4:16   ` Neo Anderson
  2005-07-07  4:32     ` Ian Lance Taylor
@ 2005-07-07  4:39     ` Jonathan Turkanis
  2005-07-07 14:54       ` Neo Anderson
  2005-07-07 11:35     ` Eljay Love-Jensen
  2 siblings, 1 reply; 10+ messages in thread
From: Jonathan Turkanis @ 2005-07-07  4:39 UTC (permalink / raw)
  To: gcc-help

[Sorry Neo, I think I sent you personal email accidentally]

Neo Anderson wrote:

 > So, what is the purpose of this warning? What possible 'damages' does this 
warning protect against?


I believe this language was added to the standard because at the time some 
systems were not able to handle files properly if they didn't end in a newline. 
This wording made it possible to provide conforming C++ implementations for 
those platforms.

I'm not sure if there still are any such systems, but because the standard has 
given implementations to freedom to do whatever they want (that's what undefined 
behavior means) if you tell them to process a file not ending in a newline, be 
warned that if you try to compile your code on another system, the compiler may 
refuse. I know, for example, that Comeau in strict mode won't compile it. For 
that matter, neither will gcc with -pedantic-errors.

Jonathan

 > And, what is the 'the behavior'?
 >
 > ----Original Message Follows----
 > From: Jonathan Turkanis <technews@kangaroologic.com>
 > To: gcc-help@gcc.gnu.org
 > Subject: Re: What is the purpose of 'warning: no newline at end of file'?
 > Date: Wed, 06 Jul 2005 21:41:20 -0600
 >
 > Neo Anderson wrote:
 >
 >> I don't even think it's a problem. Why do I need (or better have) a line ending?
 >
 >
 >
 > The C++ standard says: If a source file that is not empty does not end in a 
newline character, or ends in a newline character immediately preceded by a 
backslash character, the behavior is undefined. (2.1/1)
 >
 > Jonathan
 >
 >
 >
 >



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: What is the purpose of 'warning: no newline at end of  file'?
  2005-07-07  4:16   ` Neo Anderson
  2005-07-07  4:32     ` Ian Lance Taylor
  2005-07-07  4:39     ` Jonathan Turkanis
@ 2005-07-07 11:35     ` Eljay Love-Jensen
  2005-07-07 14:41       ` Neo Anderson
  2 siblings, 1 reply; 10+ messages in thread
From: Eljay Love-Jensen @ 2005-07-07 11:35 UTC (permalink / raw)
  To: Neo Anderson, gcc-help

Hi Neo,

--- Foo.h ---
#ifndef Foo_H_ONCE
#define Foo_H_ONCE
extern int MyFoo;
#endif // Foo_H_ONCE<NO-NEWLINE>
--- --- ---

The "<NO-NEWLINE>" is a meta to indicate that there is no newline at the end of the file.

--- Foo.cpp ---
#include "Foo.h"
#include "Bar.h"
...yada yada yada...
--- --- ---

Is Bar.h supposed to be included?  Or is the comment-to-end-of-line at the end of Foo.h supposed to comment it out?

The behavior is undefined.

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: What is the purpose of 'warning: no newline at end of file'?
  2005-07-07 11:35     ` Eljay Love-Jensen
@ 2005-07-07 14:41       ` Neo Anderson
  2005-07-07 15:23         ` Eljay Love-Jensen
  0 siblings, 1 reply; 10+ messages in thread
From: Neo Anderson @ 2005-07-07 14:41 UTC (permalink / raw)
  To: gcc-help

#include "Foo.h"

There is already a newline after it. What does the Standard say?

----Original Message Follows----
From: Eljay Love-Jensen <eljay@adobe.com>
To: Neo Anderson <neo_in_matrix@msn.com>, gcc-help@gcc.gnu.org
Subject: Re: What is the purpose of 'warning: no newline at end of  file'?
Date: Thu, 07 Jul 2005 06:38:09 -0500

Hi Neo,

--- Foo.h ---
#ifndef Foo_H_ONCE
#define Foo_H_ONCE
extern int MyFoo;
#endif // Foo_H_ONCE<NO-NEWLINE>
--- --- ---

The "<NO-NEWLINE>" is a meta to indicate that there is no newline at the end 
of the file.

--- Foo.cpp ---
#include "Foo.h"
#include "Bar.h"
...yada yada yada...
--- --- ---

Is Bar.h supposed to be included?  Or is the comment-to-end-of-line at the 
end of Foo.h supposed to comment it out?

The behavior is undefined.

HTH,
--Eljay


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: What is the purpose of 'warning: no newline at end of file'?
  2005-07-07  4:39     ` Jonathan Turkanis
@ 2005-07-07 14:54       ` Neo Anderson
  0 siblings, 0 replies; 10+ messages in thread
From: Neo Anderson @ 2005-07-07 14:54 UTC (permalink / raw)
  To: gcc-help

Thanks, that makes things much clearer for me.

----Original Message Follows----
From: Jonathan Turkanis <technews@kangaroologic.com>
To: gcc-help@gcc.gnu.org
Subject: Re: What is the purpose of 'warning: no newline at end of file'?
Date: Wed, 06 Jul 2005 22:40:28 -0600

[Sorry Neo, I think I sent you personal email accidentally]

Neo Anderson wrote:

 > So, what is the purpose of this warning? What possible 'damages' does 
this warning protect against?


I believe this language was added to the standard because at the time some 
systems were not able to handle files properly if they didn't end in a 
newline. This wording made it possible to provide conforming C++ 
implementations for those platforms.

I'm not sure if there still are any such systems, but because the standard 
has given implementations to freedom to do whatever they want (that's what 
undefined behavior means) if you tell them to process a file not ending in a 
newline, be warned that if you try to compile your code on another system, 
the compiler may refuse. I know, for example, that Comeau in strict mode 
won't compile it. For that matter, neither will gcc with -pedantic-errors.

Jonathan

 > And, what is the 'the behavior'?
 >
 > ----Original Message Follows----
 > From: Jonathan Turkanis <technews@kangaroologic.com>
 > To: gcc-help@gcc.gnu.org
 > Subject: Re: What is the purpose of 'warning: no newline at end of file'?
 > Date: Wed, 06 Jul 2005 21:41:20 -0600
 >
 > Neo Anderson wrote:
 >
 >> I don't even think it's a problem. Why do I need (or better have) a line 
ending?
 >
 >
 >
 > The C++ standard says: If a source file that is not empty does not end in 
a newline character, or ends in a newline character immediately preceded by 
a backslash character, the behavior is undefined. (2.1/1)
 >
 > Jonathan
 >
 >
 >
 >


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: What is the purpose of 'warning: no newline at end of  file'?
  2005-07-07 14:41       ` Neo Anderson
@ 2005-07-07 15:23         ` Eljay Love-Jensen
  0 siblings, 0 replies; 10+ messages in thread
From: Eljay Love-Jensen @ 2005-07-07 15:23 UTC (permalink / raw)
  To: Neo Anderson, gcc-help

Hi Neo,

>#include "Foo.h"

>There is already a newline after it. What does the Standard say?

The standard says that if you do not put in a newline at the end of Foo.h, the behavior is undefined.

The preprocessor directive #include "Foo.h" *includes* the newline at end-of-line.

No preprocessor that I know of puts in EXTRA newlines when it expands the preprocessor directives.  Putting in an EXTRA newline when the included file lacks one at the end-of-file is compiler specific (enhancement to standard) behavior.

Sincerely,
--Eljay

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2005-07-07 15:23 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-07  3:34 What is the purpose of 'warning: no newline at end of file'? Neo Anderson
2005-07-07  3:40 ` Jonathan Turkanis
2005-07-07  3:44   ` corey taylor
2005-07-07  4:16   ` Neo Anderson
2005-07-07  4:32     ` Ian Lance Taylor
2005-07-07  4:39     ` Jonathan Turkanis
2005-07-07 14:54       ` Neo Anderson
2005-07-07 11:35     ` Eljay Love-Jensen
2005-07-07 14:41       ` Neo Anderson
2005-07-07 15:23         ` Eljay Love-Jensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).