OSDev.org

The Place to Start for Operating System Developers
It is currently Sun Jun 13, 2021 6:40 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Pure Virtual Functions
PostPosted: Mon Jun 21, 2004 11:00 pm 
I am attempting to write a C++ kernel using GCC, but when i try and create classes with pure-virtual functions i get the following linker error:

"undefined reference to `___cxa_pure_virtual'"

What does this function actually do, and whats its prototype?
Cheers, Shmooze.


Top
  
 
 Post subject: RE:Pure Virtual Functions
PostPosted: Mon Jun 21, 2004 11:00 pm 
I believe it's supposed to spit out some sort of error if you somehow manage to call it.  In my "support.c" source that I link with C++ programs that don't have library support, I just have this:
        
void __pure_virtual(void)
{
}

And that appears to satisfy the linker.  You may need to change the name to ___cxa_pure_virtual, depending on the version of GCC you're using at the moment.


Top
  
 
 Post subject: RE:Pure Virtual Functions
PostPosted: Tue Jun 22, 2004 11:00 pm 
Thanks! Its strange though, I thought that the only C++ language elements needing extra support functions were new/delete, exceptions, and constructor/destructors at startup/shutdown... clearly I was wrong :(


Top
  
 
 Post subject: RE:Pure Virtual Functions
PostPosted: Tue Jun 22, 2004 11:00 pm 
BTW, the definition I used (for DJGPP) was:

extern "C" void __cxa_pure_virtual(void)
{
}

as I couldn't work out the correct name without forcing the compiler not to mangle the name.


Top
  
 
 Post subject: RE:Pure Virtual Functions
PostPosted: Tue Jun 22, 2004 11:00 pm 
I'm pretty sure virtual functions require runtime support, since their purpose is runtime polymorphism.


Top
  
 
 Post subject: RE:Pure Virtual Functions
PostPosted: Wed Jun 23, 2004 11:00 pm 
They do, hence the whole 'what function do i need' thing.


Top
  
 
 Post subject: RE:Pure Virtual Functions
PostPosted: Wed Jun 23, 2004 11:00 pm 
runtime support is not really needed, the compiler will emit the vtables and generate the proper code to do the lookups.  that function is what gets called if you somehow call a pure virtual function, which should never happen under normal circumstances.

my definitions is:

extern "C" void __cxa_pure_virtual() {
// FATAL ERROR! we just called a pure virtual function somehow...
panic("pure virtual function called in kernel!\n");
}


Top
  
 
 Post subject: RE:Pure Virtual Functions
PostPosted: Thu Jul 15, 2004 11:00 pm 
If you manage to call it, you have a problem in your build process ..


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group