forked from dftlibs/xcfun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcxx-wo-libstdcxx.cpp
50 lines (45 loc) · 1.04 KB
/
cxx-wo-libstdcxx.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* A c++ program that can be linked without libstdc++.
Requires compilation with -fno-rtti -fno-exceptions
with gcc and intel, similar options with other compilers?
*/
#include <cstdio> //Seems to be ok, requires libc
#include <cstdlib>
#include "struct_array.h"
class C
{
public:
C(int x) { data = x; mem = (int *)malloc(sizeof*mem); }
~C() { printf("Destroying C object with data = %i\n",data); free(mem); }
protected:
int data;
int *mem;
};
//Templates are ok
template<int N>
int retN()
{
// This is ok (normal static data)
static double f[] = {1,2,3};
// Creating a static object bring in locking
/* Brings in __cxa_guard_acquire/release
static C cintemplate(19); */
return N+f[0];
}
static C cstatic(5); //This is also ok with g++/gcc
int main(void)
{
C cstack(12);
array<int> a;
a.construct();
a.push_back(12);
printf("from array: %i\n",a[0]);
a[0] = 18;
printf("from array: %i\n",a[0]);
a.destruct();
/* Requires libstdc++
C *cp = new C(17);
delete cp;
*/
printf("ret12: %i\n",retN<12>());
return 0;
}