Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Does anybody know how to disable the STUPID warning gcc generates whenever I declare main as being void and taking no parameters. It is so annoying, its been standing on my nerves for ages.
GCC is not stupid, you are violating the C standard (main must return an int).
ever tried renaming main(...) to kmain(...) ?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
The function called at program startup is named main. The implementation declares no
prototype for this function. It shall be defined with a return type of int and with no
parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names may be
used, as they are local to the function in which they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent; or in some other implementation-defined manner.
Actually, in another part of the standard, they blurb about "if the return type of main() is not compatible with int". But main() implies more than that - for example, the execution of all functions registered with atexit(), which your kernel's main function probably doesn't do.
So, yes, the canon way to do it is to call the main function of a kernel kmain().
Every good solution is obvious once you've found it.
at the end or wherever you need to return and absolutely ignore the return value in the Assembly code (of your bootloader or GRUB header which calls main or whatever you want).
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
The C standard says that main() can be declared as either
int main(void);
int main(int argc, char *argv);
or in an implementation-speicific way. If, for some unknown reason to me, you want main() to be void instead of int just compile in a free-standing environment (which is also defined by the C standard) - i.e., use the -ffreestanding switch with GCC. I would like to note that it makes no difference wether you have void or int as there is no overhead - you kernel should never get to the end of the main/kmain function. Even if it did, "return 0" would just change the value of one register.
Also, the "return 0" is uneeded. The value is implied when main reaches the "}".
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
I am completely aware of the renaming solution; however, I just wondered whether it can be done with the function called "main", I just feel something is wrong when I see a kmain there!! As mentioned above the return WhateverBogusValueYouWant is an even uglier solution, I hate doing things in my code that does not make sense. I understand that the prototype of main can be implementation dependent that's why I asked. The sort of thing I was looking for is the -ffreestanding option Love4Boobies mentioned, Thanks a lot mate I am a lot more comfortable now !!!