summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2014-11-01 09:09:21 +0800
committerBernard Xiong <[email protected]>2014-11-01 09:09:21 +0800
commitb84123b0b42f64a659b15887d196159d90b72810 (patch)
tree264c0fd4b122e1882202bb83e9c0b8c92b90871f /components
parent0797e54f3f5b58e54012570d9a6ff9443d7610d8 (diff)
[C++] Add cplusplus component
Diffstat (limited to 'components')
-rw-r--r--components/cplusplus/README.md13
-rw-r--r--components/cplusplus/SConscript11
-rw-r--r--components/cplusplus/crt.cpp27
-rw-r--r--components/cplusplus/crt.h15
4 files changed, 66 insertions, 0 deletions
diff --git a/components/cplusplus/README.md b/components/cplusplus/README.md
new file mode 100644
index 0000000000..cd133effaa
--- /dev/null
+++ b/components/cplusplus/README.md
@@ -0,0 +1,13 @@
+# C++ support for RT-Thread #
+
+This is the C++ component in RT-Thread RTOS. In order to support C++ language, this component
+implement a basic environment, such as new/delete operators.
+
+Because RT-Thread RTOS is used in embedded system mostly, there are some rules for C++ applications:
+1. DOES NOT use exception.
+2. DOES NOT use Run-Time Type Information (RTTI).
+3. Template is discouraged and it easily causes code text large.
+4. Static class variables are discouraged. The time and place to call their constructor function could not be precisely controlled and make multi-threaded programming a nightmare.
+5. Multiple inheritance is strongly discouraged, as it can cause intolerable confusion.
+
+*NOTE*: For armcc compiler, the libc must be enable.
diff --git a/components/cplusplus/SConscript b/components/cplusplus/SConscript
new file mode 100644
index 0000000000..eb95aaa3c2
--- /dev/null
+++ b/components/cplusplus/SConscript
@@ -0,0 +1,11 @@
+# RT-Thread building script for component
+
+from building import *
+
+cwd = GetCurrentDir()
+src = Glob('*.cpp')
+CPPPATH = [cwd]
+
+group = DefineGroup('CPlusPlus', src, depend = ['RT_USING_CPLUSPLUS'], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/components/cplusplus/crt.cpp b/components/cplusplus/crt.cpp
new file mode 100644
index 0000000000..6fa540b9e7
--- /dev/null
+++ b/components/cplusplus/crt.cpp
@@ -0,0 +1,27 @@
+#include <rtthread.h>
+#include "crt.h"
+
+void *operator new(size_t size)
+{
+ return rt_malloc(size);
+}
+
+void *operator new[](size_t size)
+{
+ return rt_malloc(size);
+}
+
+void operator delete(void *ptr)
+{
+ rt_free(ptr);
+}
+
+void operator delete[] (void *ptr)
+{
+ return rt_free(ptr);
+}
+
+void __cxa_pure_virtual(void)
+{
+ rt_kprintf("Illegal to call a pure virtual function.\n");
+}
diff --git a/components/cplusplus/crt.h b/components/cplusplus/crt.h
new file mode 100644
index 0000000000..04fba47a60
--- /dev/null
+++ b/components/cplusplus/crt.h
@@ -0,0 +1,15 @@
+#ifndef CRT_H_
+#define CRT_H_
+
+#include <inttypes.h>
+#include <stdlib.h>
+
+void *operator new(size_t size);
+void *operator new[](size_t size);
+
+void operator delete(void * ptr);
+void operator delete[] (void *ptr);
+
+extern "C" void __cxa_pure_virtual(void);
+
+#endif