OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 9:38 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Help with program
PostPosted: Tue Nov 19, 2002 9:46 pm 
Im trying to compile a simple kernel with gcc. I am using the djgpp port on Windows ME. I am getting a really weird error and I was wondering if anybody knows what this is.

I compile my C file like this:
Code:
gcc -c hello.c -o hello.exe

I get this error:
Code:
hello.c:7:2: warning: no newline at end of file

Heres the C file:
Code:
#include <stdio.h>

int main(void)
{
       printf("Hello World\n");
       return(0);
}


Top
  
 
 Post subject: Re:Help with program
PostPosted: Tue Nov 19, 2002 10:27 pm 
Well, it's actually a warning.. it doesn't affect the output of your compiled code.

Some C compilers require a newline character at the end of your source code. GCC doesn't but it gives a friendly warning nevertheless. Just put an empty line at the end of all your .c and .h files.

- Nick


Top
  
 
 Post subject: Re:Help with program
PostPosted: Wed Nov 20, 2002 6:16 am 
Just try putting a enter at the end of the code...still a problem? Ignore it. Nothing will happen ingoring it. GCC sometimes gets confused about new lines for me to.


Top
  
 
 Post subject: Re:Help with program
PostPosted: Wed Nov 20, 2002 10:39 am 
Ah, yes, the good old "no newline at end of file" error.

I remember one time I was writing a program with either lex or yacc (I don't remember which), and I was getting tons and tons of errors with no apparent cause whatsoever. The one error that wasn't reported was the single problem that fixed them all: no newline at the end of the file. Don't ask me why it makes a difference, but for some programs it does. Fortunately, gcc is not one of them.


Top
  
 
 Post subject: Re:Help with program
PostPosted: Wed Nov 20, 2002 10:46 am 
I'd like to re-program my GCC to get rid of that warning...


Top
  
 
 Post subject: Re:Help with program
PostPosted: Wed Nov 20, 2002 11:15 am 
Thanks for the help guys. Adding a newline helped. I am confused on something though.

When I type in the lines to compile in a .batch file and run it, I get no warnings at all, not even the newline warning. But when I run it from the command-line in DOS, I get that warning.

Why is this so? Is there a flaw in gcc or does this happen to all compilers. I am new to compilers and I was wondering if anybody could explain to me why this happens.


Top
  
 
 Post subject: Re:Help with program
PostPosted: Wed Nov 20, 2002 8:01 pm 
most warnings are good warnings. I compile NAGI with these warnings:

-Wall -Winline -Wshadow -Wstrict-prototypes

It may be annoying to fix all the warnings that come up.. But it picks up sooo many mistakes that you might not catch the first time you compile the code.

Annoyed that gcc gives a warning because you don't have a newline at the end? What if somebody else picks up your code and tries to compile it on another compiler that requires it and gives an error?

I haven't used VC++ but is it true that on the highest warnng level, the compiler picks up warnings in *microsoft*'s library headers??

- Nick


Top
  
 
 Post subject: Re:Help with program
PostPosted: Thu Nov 21, 2002 12:06 am 
Tom wrote:
I'd like to re-program my GCC to get rid of that warning...


That may not be too wise; the warnings were put into the compiler for a reason. This specific warning is meant to help detect truncated source files, which, while rare in general, can sometimes be an issue when compiling source downloaded over unreliable network lines.

Most gcc warnings can be disabled, in any case. If you check the docs, you'll probably find the parropriate switch to take care of it.


Top
  
 
 Post subject: Re:Help with program
PostPosted: Thu Nov 21, 2002 6:00 am 
I said i'd like to...I know it's not a good idea ;)


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 56 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group