Visual C++ Runtime: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
New page: Since you can't link standard C++ runtime to your kernel, you'll need several functions to replace it's functionality. This article provides information on how to implement your own C++ ru...
 
m Bot: Replace deprecated source tag with syntaxhighlight
 
(6 intermediate revisions by 3 users not shown)
Line 1:
Since you can't link standard C++ runtime to your kernel, you'll need several functions to replace it's functionality. This article provides information on how to implement your own C++ runtime for Visual C++ compiler.
 
 
==Call Constructors For Global Static Variables==
This code will help to call all constructors for global static variables.
 
<sourcesyntaxhighlight lang="c">// Constructor prototypes
// Constructor prototypes
typedef void (__cdecl *_PVFV)(void);
typedef int (__cdecl *_PIFV)(void);
Line 77:
_initterm(__xc_a, __xc_z);
return true;
}</syntaxhighlight>
 
 
==new And delete Operators==
One of the first things you'll want to do is implement new and delete operators. At first, you can't really implement them, and just need to have their stubs. Later on, when you get your memory manager working, you can fully implement them. Bellow are the stubs:
 
<syntaxhighlight lang="C">void* __cdecl operator new(size_t size)
{
// Allocate memory
return 0;
}
 
</source>
 
void* __cdecl operator new[](size_t size)
{
// Allocate memory
return 0;
}
 
 
void __cdecl operator delete(void *p)
{
if (p == 0) {
return;
}
 
// Release allocated memory
}
 
void __cdecl operator delete[](void *p)
{
if (p == 0) {
return;
}
 
// Release allocated memory
}</syntaxhighlight>
 
 
If you'll want to use placement new, then you'll need to put the following implementation into a header file, and include it whenever you need it.
 
<syntaxhighlight lang="C">inline void* __cdecl operator new(size_t size, void* address)
{
return address;
}</syntaxhighlight>
 
 
==See Also==
=== Articles ===
* [[Visual Studio]]
* [[C++]]
 
=== External Links ===
* [http://msdn.microsoft.com/en-us/library/bb918180.aspx CRT Initialization on MSDN]
 
[[Category:Compilers]]
[[Category:Visual C++]]
[[Category:C++]]
[[Category:Windows]]