Help with program

Programming, for all ages and all languages.
Post Reply
beyondsociety

Help with program

Post 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:

Code: Select all

gcc -c hello.c -o hello.exe
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);
}
sonneveld

Re:Help with program

Post 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
Tom

Re:Help with program

Post 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.
ark

Re:Help with program

Post 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.
Tom

Re:Help with program

Post by Tom »

I'd like to re-program my GCC to get rid of that warning...
beyondsociety

Re:Help with program

Post 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.
sonneveld

Re:Help with program

Post 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
Schol-R-LEA

Re:Help with program

Post 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.
Tom

Re:Help with program

Post by Tom »

I said i'd like to...I know it's not a good idea ;)
Post Reply