diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-02-23 05:50:12 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-02-23 05:50:12 +0300 |
commit | c26fa67bcd051e55960dadbcd5a6ee4fd1d0fb4a (patch) | |
tree | bd487177978b767f360eca8afd428de55b8562ef /source/blender | |
parent | 765b842f9520843183bf0a3cdcd071f152bbbf9e (diff) |
BLI_utildefines: add pointer offset macro
Handy since it keeps the type of the original.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenlib/BLI_utildefines.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index de9133261fc..c7e26ce4320 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -481,6 +481,14 @@ extern "C" { /* reusable ELEM macro */ #define ARRAY_SET_ITEMS(...) { VA_NARGS_CALL_OVERLOAD(_VA_ARRAY_SET_ITEMS, __VA_ARGS__); } (void)0 +#if defined(__GNUC__) || defined(__clang__) +#define POINTER_OFFSET(v, ofs) \ + ((typeof(v))((char *)(v) + ofs)) +#else +#define POINTER_OFFSET(v, ofs) \ + ((void *)((char *)(v) + ofs)) +#endif + /* Like offsetof(typeof(), member), for non-gcc compilers */ #define OFFSETOF_STRUCT(_struct, _member) \ ((((char *)&((_struct)->_member)) - ((char *)(_struct))) + sizeof((_struct)->_member)) |