summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-11-08 07:35:55 +0100
committerTyge Løvset <[email protected]>2021-11-08 07:35:55 +0100
commite591f7c15e55eebc2f761808f5a773e42eb6638d (patch)
tree896c0e69c10c0e4759a789effcf9f8d92bcc2f20
parent42612cd91fda97600a39dce821b7c62d1bb71b27 (diff)
downloadSTC-modified-e591f7c15e55eebc2f761808f5a773e42eb6638d.tar.gz
STC-modified-e591f7c15e55eebc2f761808f5a773e42eb6638d.zip
Updated last commit. (added c_make_ptr(T, value) macro).
-rw-r--r--include/stc/ccommon.h20
1 files changed, 10 insertions, 10 deletions
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index 70152175..06ccfc04 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -73,23 +73,23 @@
#define c_container_of(ptr, type, member) \
((type *)((char *)(ptr) - offsetof(type, member)))
-#if __cplusplus
+#ifndef __cplusplus
+# 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))
+#else
# 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_make_ptr(T, value) memcpy(c_new(T), &(T){value}, sizeof(T))
#endif
#ifndef c_malloc
-#define c_malloc(sz) malloc(sz)
-#define c_calloc(n, sz) calloc(n, sz)
-#define c_realloc(p, sz) realloc(p, sz)
-#define c_free(p) free(p)
+# define c_malloc(sz) malloc(sz)
+# define c_calloc(n, sz) calloc(n, sz)
+# define c_realloc(p, sz) realloc(p, sz)
+# define c_free(p) free(p)
#endif
#define c_swap(T, x, y) do { T _c_t = x; x = y; y = _c_t; } while (0)