C++ Con/Destructor implementation question
Posted: Wed Jun 03, 2009 7:57 am
When writing aKernel in C++, I have a few questions about implementation of C++ core features that need programmer definition.
I know that new, delete, and several other key features need redefining. But do I also need to implement my own malloc() function? I know that memcpy() memset(), and memcmp(), etc need to be redefined without Standard Lib support.
Also: Since I've looked all over, and found nothing on this:
I've read that the compiler calls constructors and destructors at the end of the block for which the object was defined. Yet, in all of the tutorials i've seen so far, they talk about an implementation of the functions _main() and _atexit() that call destructos upon the opening and closing of the PROGRAM, for GLOBAL vars.
Do these also get called at the end of blacks? for example:
Will the destructors for objects that are not declared directly within main, or as global vars, be called by the program if I only implement these tow functions, _main(), and _atexit()?
Thanks in advance. I understand that this may have been loked at elsewhere, but I've searched, and found nothing comprehensible.
I know that new, delete, and several other key features need redefining. But do I also need to implement my own malloc() function? I know that memcpy() memset(), and memcmp(), etc need to be redefined without Standard Lib support.
Also: Since I've looked all over, and found nothing on this:
I've read that the compiler calls constructors and destructors at the end of the block for which the object was defined. Yet, in all of the tutorials i've seen so far, they talk about an implementation of the functions _main() and _atexit() that call destructos upon the opening and closing of the PROGRAM, for GLOBAL vars.
Do these also get called at the end of blacks? for example:
Code: Select all
class foo
{
foo(){}; //constructor;
~foo(){}; //destructor;
void bar(void){}
};
void func1(){
foo foo_obj;
}
int main(void)
{
func1();
//Does the destructor for the foo object initialized in here get called?
{
foo foo_obj2
//This var was initialized in its own block. Will the destructor be called?
}
};
Thanks in advance. I understand that this may have been loked at elsewhere, but I've searched, and found nothing comprehensible.