diff --git a/nuklear.h b/nuklear.h index 6f832d1..bcf0843 100644 --- a/nuklear.h +++ b/nuklear.h @@ -5697,12 +5697,10 @@ struct nk_context { #define NK_ALIGN_PTR_BACK(x, mask)\ (NK_UINT_TO_PTR((NK_PTR_TO_UINT((nk_byte*)(x)) & ~(mask-1)))) +#if defined(__GNUC__) || defined(__clang__) +#define NK_OFFSETOF(st,m) (__builtin_offsetof(st,m)) +#else #define NK_OFFSETOF(st,m) ((nk_ptr)&(((st*)0)->m)) -#define NK_CONTAINER_OF(ptr,type,member)\ - (type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - NK_OFFSETOF(type, member))) - -#ifdef __cplusplus -} #endif #ifdef __cplusplus @@ -5712,12 +5710,18 @@ template struct nk_helper{enum {value = nk_alignof::value};} template struct nk_alignof{struct Big {T x; char c;}; enum { diff = sizeof(Big) - sizeof(T), value = nk_helper::value};}; #define NK_ALIGNOF(t) (nk_alignof::value) -#elif defined(_MSC_VER) -#define NK_ALIGNOF(t) (__alignof(t)) #else -#define NK_ALIGNOF(t) ((char*)(&((struct {char c; t _h;}*)0)->_h) - (char*)0) +#define NK_ALIGNOF(t) NK_OFFSETOF(struct {char c; t _h;}, _h) #endif +#define NK_CONTAINER_OF(ptr,type,member)\ + (type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - NK_OFFSETOF(type, member))) + +#ifdef __cplusplus +} +#endif + + #endif /* NK_NUKLEAR_H_ */ #ifdef NK_IMPLEMENTATION @@ -29525,6 +29529,7 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// - [yy]: Minor version with non-breaking API and library changes /// - [zz]: Bug fix version with no direct changes to API /// +/// - 2021/09/08 (4.08.1) - Use compiler builtins for NK_OFFSETOF when possible /// - 2021/08/17 (4.08.0) - Implemented 9-slice scaling support for widget styles /// - 2021/08/16 (4.07.5) - Replace usage of memset in nk_font_atlas_bake with NK_MEMSET /// - 2021/08/15 (4.07.4) - Fix conversion and sign conversion warnings diff --git a/package.json b/package.json index 646c364..970e6c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nuklear", - "version": "4.08.0", + "version": "4.08.1", "repo": "Immediate-Mode-UI/Nuklear", "description": "A small ANSI C gui toolkit", "keywords": ["gl", "ui", "toolkit"], diff --git a/src/CHANGELOG b/src/CHANGELOG index ae3c726..92448cb 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -8,6 +8,7 @@ /// - [yy]: Minor version with non-breaking API and library changes /// - [zz]: Bug fix version with no direct changes to API /// +/// - 2021/09/08 (4.08.1) - Use compiler builtins for NK_OFFSETOF when possible /// - 2021/08/17 (4.08.0) - Implemented 9-slice scaling support for widget styles /// - 2021/08/16 (4.07.5) - Replace usage of memset in nk_font_atlas_bake with NK_MEMSET /// - 2021/08/15 (4.07.4) - Fix conversion and sign conversion warnings diff --git a/src/nuklear.h b/src/nuklear.h index 45fb747..65db6a1 100644 --- a/src/nuklear.h +++ b/src/nuklear.h @@ -5476,12 +5476,10 @@ struct nk_context { #define NK_ALIGN_PTR_BACK(x, mask)\ (NK_UINT_TO_PTR((NK_PTR_TO_UINT((nk_byte*)(x)) & ~(mask-1)))) +#if defined(__GNUC__) || defined(__clang__) +#define NK_OFFSETOF(st,m) (__builtin_offsetof(st,m)) +#else #define NK_OFFSETOF(st,m) ((nk_ptr)&(((st*)0)->m)) -#define NK_CONTAINER_OF(ptr,type,member)\ - (type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - NK_OFFSETOF(type, member))) - -#ifdef __cplusplus -} #endif #ifdef __cplusplus @@ -5491,10 +5489,16 @@ template struct nk_helper{enum {value = nk_alignof::value};} template struct nk_alignof{struct Big {T x; char c;}; enum { diff = sizeof(Big) - sizeof(T), value = nk_helper::value};}; #define NK_ALIGNOF(t) (nk_alignof::value) -#elif defined(_MSC_VER) -#define NK_ALIGNOF(t) (__alignof(t)) #else -#define NK_ALIGNOF(t) ((char*)(&((struct {char c; t _h;}*)0)->_h) - (char*)0) +#define NK_ALIGNOF(t) NK_OFFSETOF(struct {char c; t _h;}, _h) #endif +#define NK_CONTAINER_OF(ptr,type,member)\ + (type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - NK_OFFSETOF(type, member))) + +#ifdef __cplusplus +} +#endif + + #endif /* NK_NUKLEAR_H_ */