Skip to content

Commit

Permalink
compiler.h: add DECLARE_FLEX_ARRAY and struct_size
Browse files Browse the repository at this point in the history
Import from FreeBSD.
  • Loading branch information
marckleinebudde committed May 10, 2023
1 parent 6af7be2 commit 0207095
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions include/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@
(type *)((char *)_p - offsetof(type, member)); \
})

#define struct_size(ptr, field, num) \
(offsetof(__typeof(*(ptr)), field) + sizeof((ptr)->field[0]) * (num))

#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))

#define DECLARE_FLEX_ARRAY(_t, _n) \
struct { \
struct { } __dummy_ ## _n; \
_t _n[0]; \
}

#endif /* _LINUXKPI_LINUX_COMPILER_H_ */

0 comments on commit 0207095

Please sign in to comment.