Page 2 of 2

Re: how to use C++ with classes

Posted: Wed Aug 27, 2008 9:59 am
by sebihepp
Yes, I have read this article albeva.
And I have implemented my own version of this function.
But why does my kernel calls this function?

Re: how to use C++ with classes

Posted: Thu Aug 28, 2008 5:57 am
by sebihepp
Can't anyone help me? I only need to know why my VirtualFunctionHandler is always called although
there is no virtual function. If it helps I can upload my project into a webspace and write down a link here.

Sebihepp

Re: how to use C++ with classes

Posted: Thu Aug 28, 2008 9:35 am
by albeva
Read the article again then:
Why?

It is a requirement of C++ to provide a backup function to call when a virtual function cannot be called.

Re: how to use C++ with classes

Posted: Fri Aug 29, 2008 9:36 am
by sebihepp
Sorry, I must be blind. Or it is because my native language is german.
"It is a requirement of C++ to provide a backup function to call when a virtual function cannot be called. "
I always thought, if the compiler cannot call a virtual function, it will report an error?
And just when the instruction "call _main" is executed, this function mentioned above is
called instead.

I use C instead of C++ now, but the source of this error interests me. So if anyone have time to help
me, he is welcome.

Greetings Sebihepp

Re: how to use C++ with classes

Posted: Fri Aug 29, 2008 11:34 am
by madeofstaples
albeva wrote:Read the article again then:
Why?

It is a requirement of C++ to provide a backup function to call when a virtual function cannot be called.
But sebihepp's question was not just "why", it was "why is my virtual function handler always called??" and just below the text you quoted, the article continues:
If during runtime your kernel detects that a call to a pure virtual function couldn't be made, it calls the above functions. These functions should actually never be called, because without hacks (or through undefined behaviour of your kernel) it is not possible to instantiate a class that doesn't define all pure virtual functions. But nonetheless you have to define these functions or your linker will complain about unresolved symbols.
So either I'm confused, or the actual answer to sebihepp is that he has overwritten the virtual function table of his object... ?

Re: how to use C++ with classes

Posted: Fri Aug 29, 2008 12:59 pm
by sebihepp
@madeofstaples:
Yes, I am thinking that too. But I have no objects!!! :shock:
I have only a main function with a "while (1);" in it.

Sebihepp

Re: how to use C++ with classes

Posted: Fri Aug 29, 2008 3:22 pm
by albeva
see assembly output. It might be some gcc internal stuff. Where it would want to get the address of this function...

Re: how to use C++ with classes

Posted: Sun Aug 31, 2008 9:20 am
by codemastersnake
Combuster wrote:In the category required knowledge:

USE A C++ COMPILER AND NOT A C COMPILER.

I seriously doubt you should be developing an OS when you even failed to reach "hello world" level :shock:
Don't discourage anybody! [-X