Page 1 of 1

just a warning of gcc

Posted: Thu Mar 17, 2005 12:37 am
by njmarshal
It is a good ideal to compile the OS kernel with gcc
and nasm


but when I compile my .c file it alwaays return me a warning like this:

warning: no newline at end of file

I have a manual of gcc ,but when I look throught at it ,I can not find anything about the warning !

It is may not so important,because the .o file can be used,but it is so boring !

how can I make it.

Re:just a warning of gcc

Posted: Thu Mar 17, 2005 1:23 am
by Candy
add a new line at the end of the file... Your last line should always be blank, in windows-terms. In other words, you should terminate each line that does contain something with a newline.

If you editor strips off the last newlines get a better editor.

Re:just a warning of gcc

Posted: Thu Mar 17, 2005 1:28 am
by Poseidon
why is a newline at the end of the file actually needed? :)

Re:just a warning of gcc

Posted: Thu Mar 17, 2005 1:58 am
by njmarshal
thanks for your attention ,I have solve this warning !
but now I have a other thing,that I can not understand !

if I creat files as head.h and kernel.c
here is some code in head.h

Code: Select all

#define  byte unsigned char
and in kernel.c I write like this :

Code: Select all

#include "head.h"
//something else

byte   kkkkk=1;
 //others
and gcc compile the kernel.c,it brings to me a lot of error
but if I write this
unsigned char kkkk=1;
it is ok?

who can explain why "#define byte unsigned char"does not work as I think!or maybe I forget some parameters to gcc

thanks for your help ahead!

Re:just a warning of gcc

Posted: Thu Mar 17, 2005 2:03 am
by Solar
It isn't exactly needed - that's why it's a warning, instead of an error.

But imagine:

Code: Select all

// foo.h

void somecode() // no newline at end of this line
And:

Code: Select all

// main.c

#include <foo.h>
#include <bar.h>
If your preprocessor isn't smart, you might lose the [tt]#include <bar.h>[/tt] in the comment from [tt]foo.h[/tt]...

Just play it safe, end your files with a newline. Even if all you do it for is to satisfy the compiler. The compiler is your friend, not your enemy.

Re:just a warning of gcc

Posted: Thu Mar 17, 2005 2:05 am
by Curufir
Use typedef not define.

Re:just a warning of gcc

Posted: Thu Mar 17, 2005 2:11 am
by njmarshal
you mean typedef like this:

in head.h
typedef unsigned char byte

but it seems like not work !

Re:just a warning of gcc

Posted: Thu Mar 17, 2005 3:13 am
by Solar
Show us the GCC errors in question, and we might be better able to help.

Re:just a warning of gcc

Posted: Thu Mar 17, 2005 4:00 am
by Pype.Clicker
1. you should make sure your header file is processed correctly. It has to be somewhere in the "virtual path" to be seen by GCC.

2. you should have a ";" at the end of your typedef line

Code: Select all

typedef unsigned char byte;
3. seeing the error/warning gcc produces would indeed help alot.