diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-04-28 14:14:46 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-04-28 16:15:47 +0300 |
commit | 1f9fe0626fc0f6de449b62d88763faf8290e93b5 (patch) | |
tree | 86672a1caec1dd29b81ff71d3d2d800164cd9fa5 /source/blender/blenlib | |
parent | 5e423775da5c85a0340d7acd302f6d3cbaa6b159 (diff) |
BLI_utildefines: add MEMSET_STRUCT_OFS macro
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_utildefines.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index 2ddc8faa8b1..d817aa95c74 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -493,8 +493,11 @@ extern "C" { #define OFFSETOF_STRUCT(_struct, _member) \ ((((char *)&((_struct)->_member)) - ((char *)(_struct))) + sizeof((_struct)->_member)) -/* memcpy, skipping the first part of a struct, - * ensures 'struct_dst' isn't const and that the offset can be computed at compile time */ +/** + * memcpy helper, skipping the first part of a struct, + * ensures 'struct_dst' isn't const and the offset can be computed at compile time. + * This isn't inclusive, the value of \a member isn't copied. + */ #define MEMCPY_STRUCT_OFS(struct_dst, struct_src, member) { \ CHECK_TYPE_NONCONST(struct_dst); \ ((void)(struct_dst == struct_src), \ @@ -503,6 +506,13 @@ extern "C" { sizeof(*(struct_dst)) - OFFSETOF_STRUCT(struct_dst, member))); \ } (void)0 +#define MEMSET_STRUCT_OFS(struct_var, value, member) { \ + CHECK_TYPE_NONCONST(struct_var); \ + memset((char *)(struct_var) + OFFSETOF_STRUCT(struct_var, member), \ + value, \ + sizeof(*(struct_var)) - OFFSETOF_STRUCT(struct_var, member)); \ +} (void)0 + /* Warning-free macros for storing ints in pointers. Use these _only_ * for storing an int in a pointer, not a pointer in an int (64bit)! */ #define SET_INT_IN_POINTER(i) ((void *)(intptr_t)(i)) |