Page 1 of 1
Help with program
Posted: Tue Nov 19, 2002 9:46 pm
by beyondsociety
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:
I get this error:
Code: Select all
hello.c:7:2: warning: no newline at end of file
Heres the C file:
Code: Select all
#include <stdio.h>
int main(void)
{
printf("Hello World\n");
return(0);
}
Re:Help with program
Posted: Tue Nov 19, 2002 10:27 pm
by sonneveld
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
Re:Help with program
Posted: Wed Nov 20, 2002 6:16 am
by Tom
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.
Re:Help with program
Posted: Wed Nov 20, 2002 10:39 am
by ark
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.
Re:Help with program
Posted: Wed Nov 20, 2002 10:46 am
by Tom
I'd like to re-program my GCC to get rid of that warning...
Re:Help with program
Posted: Wed Nov 20, 2002 11:15 am
by beyondsociety
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.
Re:Help with program
Posted: Wed Nov 20, 2002 8:01 pm
by sonneveld
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
Re:Help with program
Posted: Thu Nov 21, 2002 12:06 am
by Schol-R-LEA
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.
Re:Help with program
Posted: Thu Nov 21, 2002 6:00 am
by Tom
I said i'd like to...I know it's not a good idea