3

As the title says, what are they and what's the difference?

Some examples:

dmain:

void dmain(void* mbd, unsigned int magic)

kmain:

void kmain( void* mbd, unsigned int magic )

P.S. I found a similar post here but it was about wmain:

What is the difference between wmain and main?

Also _tmain:

What is the difference between _tmain() and main() in C++?

__

They take the same arguments but is there a difference? And any links to some info this so I could learn is appreciated, google yielded weird results...

Also, is there an official sort of like 'man' pages of C?

Community
  • 1
  • 1
krack krackerz
  • 1,399
  • 2
  • 9
  • 13
  • Don't know about _man pages_ for C, but there is the ISO/IEC C standard 'C99'. This URL has a link to the latest version of the C99 standard: http://open-std.org/JTC1/SC22/WG14/www/standards – ArjunShankar Mar 02 '12 at 08:55
  • 1
    As these are non standard functions/"main" functions, you have to tell us where you found these. – nos Mar 02 '12 at 08:58
  • 1
    These are implementation defined, Have a look at my answer here: [What these C's main function indicates?](http://stackoverflow.com/questions/9091711/what-these-cs-main-function-indicates) – Alok Save Mar 02 '12 at 09:02
  • the dmain and kmain are from kernel code, one's from: http://wiki.osdev.org/Bare_Bones#kernel.c Which gives a limited explanation. Finding _tmain and wmain just made me more confused... – krack krackerz Mar 02 '12 at 09:20
  • Well... from that wiki it seems that kmain is the entry point of the kernel. I do not know what you want to know about it? (I *suppose* that the real `main()` is hidden in kmain.cpp, see example listing, but this is just my speculation) – Veger Mar 02 '12 at 09:52
  • @krack krackerz There's nothing special in C about a kmain or dmain function. However the people at osdev.org wrote their bootloader so it starts running the kmain function in their code. – nos Mar 02 '12 at 12:50
  • so essentially I could make up my own name for main. How about calling it "primary"? Also, since main is an object, does this mean that it isnt in this example anymore? – krack krackerz Mar 08 '12 at 06:31

1 Answers1

3

You seem to be referring to this tutorial on OSDev.org.

If you’ll notice, this is not a standard C program with main() as its entry point. In fact, the page shows two entry points: one written in Assembler in a way for GRUB to find & load, and which sets up & loads the second, kmain(), which is written in C. The writers use the name kmain to mean “kernel main”; presumably dmain is the entry point for drivers & would stand for “driver main”.

C makes a distinction between “freestanding” and “hosted” implementations. Hosted is what you’re probably more familiar with; the standard C library is available, and all programs start at the main function.

OS kernels are (often) good examples of freestanding environments. The C library will likely not be available, for example (except for certain headers like stddef.h & stdarg.h; see the standard for details). Also, the entry point is not defined by the standard anymore. The OSDev.org tutorial is making a special point of that fact, by explicitly defining its entry point with a different name.

You could probably run the tutorial renaming kmain to main, but note that it’s still void main(void*, unsigned int), not int main(int, char**); in fact that sort of confusion is likely part of the reason the writers chose to use a different name. But is is just a convention they’ve selected, not anything standardized.

J. C. Salomon
  • 4,143
  • 2
  • 29
  • 38