From e591f7c15e55eebc2f761808f5a773e42eb6638d Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Mon, 8 Nov 2021 07:35:55 +0100 Subject: Updated last commit. (added c_make_ptr(T, value) macro). --- include/stc/ccommon.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'include') 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 # define c_new(T) static_cast(c_malloc(sizeof(T))) # define c_new_n(T, n) static_cast(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) -- cgit v1.2.3