diff options
| -rw-r--r-- | include/stc/ccommon.h | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 6e6aefd2..70152175 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -74,13 +74,16 @@ ((type *)((char *)(ptr) - offsetof(type, member)))
#if __cplusplus
-#define c_new(T) static_cast<T*>(c_malloc(sizeof(T)))
-#define c_new_n(T, n) static_cast<T*>(c_malloc(sizeof(T)*(n)))
-#define c_make(T) T
+# include <new>
+# define c_new(T) static_cast<T*>(c_malloc(sizeof(T)))
+# define c_new_n(T, n) static_cast<T*>(c_malloc(sizeof(T)*(n)))
+# define c_make(T) T
+# define c_make_ptr(T, value) new (c_new(T)) T{value}
#else
-#define c_new(T) c_malloc(sizeof(T))
-#define c_new_n(T, n) c_malloc(sizeof(T)*(n))
-#define c_make(T) (T)
+# define c_new(T) c_malloc(sizeof(T))
+# define c_new_n(T, n) c_malloc(sizeof(T)*(n))
+# define c_make(T) (T)
+# define c_make_ptr(T, value) memcpy(c_new(T), &(T){value}, sizeof(T))
#endif
#ifndef c_malloc
#define c_malloc(sz) malloc(sz)
|
