xref: /haiku/headers/private/kernel/util/kernel_cpp.h (revision 67bce78b48ed6d01b5a8eef89f5694c372b7e0a1)
1 #ifndef KERNEL_CPP_H
2 #define KERNEL_CPP_H
3 /* cpp - C++ in the kernel
4 **
5 ** Initial version by Axel Dörfler, axeld@pinc-software.de
6 ** This file may be used under the terms of the OpenBeOS License.
7 */
8 
9 #ifdef __cplusplus
10 
11 #include <new>
12 #include <stdlib.h>
13 
14 #if _KERNEL_MODE
15 
16 using namespace std;
17 extern const nothrow_t std::nothrow;
18 
19 // Oh no! C++ in the kernel! Are you nuts?
20 //
21 //	- no exceptions
22 //	- (almost) no virtuals (well, the Query code now uses them)
23 //	- it's basically only the C++ syntax, and type checking
24 //	- since one tend to encapsulate everything in classes, it has a slightly
25 //	  higher memory overhead
26 //	- nicer code
27 //	- easier to maintain
28 
29 
30 inline void *
31 operator new(size_t size) throw (std::bad_alloc)
32 {
33 	// we don't actually throw any exceptions, but we have to
34 	// keep the prototype as specified in <new>, or else GCC 3
35 	// won't like us
36 	return malloc(size);
37 }
38 
39 
40 inline void *
41 operator new[](size_t size) throw (std::bad_alloc)
42 {
43 	return malloc(size);
44 }
45 
46 
47 inline void *
48 operator new(size_t size, const std::nothrow_t &) throw ()
49 {
50 	return malloc(size);
51 }
52 
53 
54 inline void *
55 operator new[](size_t size, const std::nothrow_t &) throw ()
56 {
57 	return malloc(size);
58 }
59 
60 
61 inline void
62 operator delete(void *ptr) throw ()
63 {
64 	free(ptr);
65 }
66 
67 
68 inline void
69 operator delete[](void *ptr) throw ()
70 {
71 	free(ptr);
72 }
73 
74 // we're using virtuals
75 extern "C" void __pure_virtual();
76 
77 #endif	// #if _KERNEL_MODE
78 #endif	// __cplusplus
79 
80 #endif	/* KERNEL_CPP_H */
81