C++: Difference between revisions

1,063 bytes added ,  14 years ago
[unchecked revision][unchecked revision]
m (Killing "PlusPlus" for "C++ Bare Bones" too)
Line 56:
====Enabling global objects====
Global or static objects have to be constructed by the environment before they are available for C++ code. Care should be taken if global/static objects need new and delete in their constructors. In this case it is best to construct global/static objects only after your kernel heap is ready for use. Not doing so can cause an object to attempt to allocate memory via the non-working new operator. This also simplifies the storing of the destructor functions in <tt>__cxa_atexit</tt>, because you don't have to use a static and fixed-size structure.
 
According to the [http://refspecs.freestandards.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/baselib---cxa-atexit.html Itanium C++ Application Binary Interface], the function <tt>__cxa_atexit</tt> is used to register a destructor to be called when a shared library is to be unloaded. This function should insert a function pointer, with (max) one accompanying argument, and the handle of the object or shared resource to be destroyed, into a table. In the source example for an implementation of <tt>__cxa_atexit</tt>, the <tt>struct object[32]</tt> array acts as the table.
 
This is why, below, the function <tt>__cxa_atexit</tt> is defined as:
<source lang="cpp">
int __cxa_atexit(void (*destructor_func)(void *), void *arg, void *__dso_handle);
</source>
Such that, as explained above, <tt>'destructor_func'</tt> is the handle for a destructor function, <tt>'arg'</tt> as defined by the ABI is the single argument it may take, and <tt>__dso_handle</tt> is <em>similar</em> to the C++ This pointer. But for more complex objects and resources this is dodgy.
=====GCC (version < 3.2)=====
 
Anonymous user