C++: Difference between revisions

841 bytes removed ,  10 years ago
The "start up code" section is inaccurate and this is already covered in Bare Bones.
[unchecked revision][unchecked revision]
mNo edit summary
(The "start up code" section is inaccurate and this is already covered in Bare Bones.)
Line 4:
 
A lot of features C++ offers can be used on-the-fly; they require no additional support or code to use them properly (e.g. templates, classes, inheritance, virtual functions). There are however other parts of C++ that do require runtime support, which will be discussed in this article.
 
== Start-up code ==
By default, '''g++''' tries to link in start-up code. Setup that needs to be done before the entry point (e.g. '''main''') is called, but also the shutdown process needed after it returns. This is all fine in a hosted environment (e.g. for C++ programs), but you don't want to have it in your kernel (and it wouldn't compile, either). Disable it by adding <tt>-nostartfiles</tt> to your '''gcc''' or '''g++''' arguments.
 
We need to do this for the same reason as for C code. Start-up code needed for C/C++ is OS-specific and sometimes even compiler-specific. In a freestanding environment, you'll need to implement your own start-up code to configure the stack (and possibly other language-specific features). Finally, your [[Bootloader]] has to know where this start-up code begins and it has to jump to that address.
 
== Pure virtual functions ==
Anonymous user