warning : no new line at end of file

Discussion in 'C Programming' started by Sameer, Dec 29, 2005.

  1. Sameer

    Sameer Guest

    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
     
    Sameer, Dec 29, 2005
    #1
    1. Advertising

  2. Hi,

    Can you please type the program you are trying to compile.

    It would be helpful for us if you tell us the compilation environment.
    for e.g. OS used and compiler version used.

    Rahul
     
    Rahul Chandok, Dec 29, 2005
    #2
    1. Advertising

  3. "Sameer" <> writes:
    > when i compile my C programs (even 2 line progs) give the warning, no
    > new line at end of file.
    > What does this mean ?


    It means there's no newline at the end of the file. What do you think
    it means?

    In your text editor, add a newline to the end of the file you're
    trying to compile. (Some editors do this automatically; yours
    apparently doesn't.)

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Dec 29, 2005
    #3
  4. Sameer

    Chuck F. Guest

    Sameer wrote:
    >
    > 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 ?


    It means that there was no newline character at the end of the
    source file. You must be failing to hit <ret> (or <enter>) after
    typing the last source line in your editor.

    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
    More details at: <http://cfaj.freeshell.org/google/>
     
    Chuck F., Dec 29, 2005
    #4
  5. Sameer

    Richard Bos Guest

    "Sameer" <> wrote:

    > when i compile my C programs (even 2 line progs) give the warning, no
    > new line at end of file.


    It means, surprise, surprise, that there is no new-line at the end of
    your source file. Quoth the Standard:

    # A source file that is not empty shall end in a new-line character

    Richard
     
    Richard Bos, Dec 29, 2005
    #5
  6. Sameer

    Sameer Guest

    this is the source code :

    #include <stdio.h>

    main()
    {
    printf("hi\n") ;

    }
    when i compile it i get
    warning: no new line at end of file
    I am using madrake linux and compiling it with gcc
     
    Sameer, Dec 29, 2005
    #6
  7. Sameer

    Sameer Guest

    thanks a lot. now it is working fine.
     
    Sameer, Dec 29, 2005
    #7
  8. Sameer

    John Smith Guest

    > It means, surprise, surprise, that there is no new-line at the end of
    > your source file. Quoth the Standard:
    >
    > # A source file that is not empty shall end in a new-line character


    So the next obvious question is to ask why it is this way?

    I personally think it's one of the most dumb restrictions ever made. Does it
    change anything about how the program is compiled? No! I mean, who cares
    about blank lines. It's the code which is important.

    Apple also seems to have disabled this in their version of gcc on Mac OS X.

    -- John
     
    John Smith, Dec 29, 2005
    #8
  9. [Followups set to comp.lang.c]

    John Smith said:

    >> It means, surprise, surprise, that there is no new-line at the end of
    >> your source file. Quoth the Standard:
    >>
    >> # A source file that is not empty shall end in a new-line character

    >
    > So the next obvious question is to ask why it is this way?


    Presumably because a source file is intended to be a text file, and a text
    file comprises zero or more lines, and a line comprises zero or more
    characters terminated by a newline character.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, Dec 29, 2005
    #9
  10. Sameer

    Richard Bos Guest

    "John Smith" <> wrote:

    > > It means, surprise, surprise, that there is no new-line at the end of
    > > your source file. Quoth the Standard:
    > >
    > > # A source file that is not empty shall end in a new-line character

    >
    > So the next obvious question is to ask why it is this way?


    Because there are OSes where a text file is stranger even than the
    mindset of a Unix-head.

    > I personally think it's one of the most dumb restrictions ever made. Does it
    > change anything about how the program is compiled? No! I mean, who cares
    > about blank lines.


    The restriction is not on blank lines; the restriction is that the final
    line, like all the others, must be properly terminated.

    Not all the world is a toy OS from Berzerkeley, you know.

    Richard
     
    Richard Bos, Dec 29, 2005
    #10
  11. Sameer

    Afifov Guest

    could it be that you forgot void main()?!
     
    Afifov, Dec 29, 2005
    #11
  12. Afifov said:

    > could it be that you forgot void main()?!


    I hope that was intended ironically. In C, main returns int.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, Dec 29, 2005
    #12
  13. Thu, Dec 29, 2005 at 10:48:30, js (John Smith) wrote about "warning : no new line at end of file":

    >> # A source file that is not empty shall end in a new-line character

    JS> So the next obvious question is to ask why it is this way?

    Because unterminated text line isn't proper text line.

    JS> I personally think it's one of the most dumb restrictions ever made. Does it
    JS> change anything about how the program is compiled? No! I mean, who cares
    JS> about blank lines. It's the code which is important.
    JS> Apple also seems to have disabled this in their version of gcc on Mac OS X.

    Stock gcc doesn't require termination of last line, but warns for
    its.


    -netch-
     
    Valentin Nechayev, Dec 29, 2005
    #13
  14. Sameer

    Afifov Guest

    you must declare main to be int and return 0. The person with the first
    post excluded the return statement, which i was referring to.
     
    Afifov, Dec 29, 2005
    #14
  15. Sameer

    Chuck F. Guest

    Afifov wrote:
    >
    > you must declare main to be int and return 0. The person with
    > the first post excluded the return statement, which i was
    > referring to.


    Who is 'you'? The first post in this newsgroup occurred something
    like 40 years ago, and I don't think it is available anywhere.
    Some people cooperate and include proper context and attributions
    in their reply articles. Other rude ones don't bother and just
    waste everybodies time and bandwidth.

    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
    More details at: <http://cfaj.freeshell.org/google/>
     
    Chuck F., Dec 29, 2005
    #15
  16. Sameer

    Richard Bos Guest

    "Afifov" <> wrote:

    > you must


    _Who_ must? Learn to quote context! This is not a web board where
    anything goes.

    Richard
     
    Richard Bos, Dec 29, 2005
    #16
  17. "Sameer" <> writes:

    > 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 ?


    It means that there isn't a newline at the end of the file.

    /Niklas Norrthon
     
    Niklas Norrthon, Dec 29, 2005
    #17
  18. Samer wrote earlier in the thread:

    >> 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 ?



    "Afifov" <> writes:

    > could it be that you forgot void main()?!


    Please provide context!!!

    May I ask why you think a warning about a missing newline would
    have anything to do with "void main()" whatever that is?

    By the way in C main returns int. Always!

    /Niklas Norrthon
     
    Niklas Norrthon, Dec 29, 2005
    #18
  19. In article <4all.nl>,
    Richard Bos <> wrote:
    >"Afifov" <> wrote:
    >
    >> you must

    >
    >_Who_ must? Learn to quote context! This is not a web board where
    >anything goes.


    From his point of view, it *is*.
     
    Kenny McCormack, Dec 29, 2005
    #19
  20. In article <>,
    Chuck F. <> wrote:
    >Afifov wrote:
    >>
    >> you must declare main to be int and return 0. The person with
    >> the first post excluded the return statement, which i was
    >> referring to.

    >
    >Who is 'you'? The first post in this newsgroup occurred something
    >like 40 years ago, and I don't think it is available anywhere.
    >Some people cooperate and include proper context and attributions
    >in their reply articles. Other rude ones don't bother and just
    >waste everybodies time and bandwidth.


    You (and others, such as Keith) are wasting your breath. They'll never get
    it. And I'll tell you why.

    Imagine that there's a mouse - and the mouse is the Usenet. You and I can
    see that it is a mouse and we behave accordingly. But now there is a class
    of users (we'll call them "googlers") that are wearing these funny weird
    glasses that make them see not a mouse, but an elephant. Seeing an
    elephant (i.e., the Usenet as a web page), they also behave accordingly.
    And no amount of verbiage from us is going to convince them that it's not
    an elephant - that it is only a mouse.

    To make this more clear, to a googler, it doesn't make any sense to "quote"
    (whatever the heck that is...), in fact, to do so would be absurd, when all
    the rest of the articles in the thread are right there in front of their
    faces (just as clear as the trunk on that mouse, er, elephant). And no
    amount of verbiage from us is going to convince them not to believe what
    they see. The point is you can *never* convince someone that what they see
    isn't reality. The only way you can address the problem is to help them
    fix their eyesight (or help them remove their funny glasses).
     
    Kenny McCormack, Dec 29, 2005
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page