summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-11-08 07:29:56 +0100
committerTyge Løvset <[email protected]>2021-11-08 07:29:56 +0100
commit42612cd91fda97600a39dce821b7c62d1bb71b27 (patch)
tree1b5a31c8a74337d16f1d21d937f7092770ffd123
parentb6df2ea7a5aa0a31977c6d0b72efef025899b4c5 (diff)
downloadSTC-modified-42612cd91fda97600a39dce821b7c62d1bb71b27.tar.gz
STC-modified-42612cd91fda97600a39dce821b7c62d1bb71b27.zip
Added c_make_ptr(T, value) macro.
-rw-r--r--include/stc/ccommon.h15
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)