From 10d1fde5756d9535b2301806c01d0b029661eddc Mon Sep 17 00:00:00 2001 From: Furquan Shaikh Date: Wed, 19 Apr 2017 19:25:52 -0700 Subject: commonlib/helpers: Add helper macro for member_size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit member_size macro provides the size of a structure member. Change-Id: I53e9c9bf70b3ebed0d15e8258111b17e50667a74 Signed-off-by: Furquan Shaikh Reviewed-on: https://review.coreboot.org/19384 Reviewed-by: Aaron Durbin Tested-by: build bot (Jenkins) Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Paul Menzel --- src/commonlib/include/commonlib/helpers.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/commonlib/include/commonlib/helpers.h b/src/commonlib/include/commonlib/helpers.h index d2ef94196d..0a796ba85b 100644 --- a/src/commonlib/include/commonlib/helpers.h +++ b/src/commonlib/include/commonlib/helpers.h @@ -85,6 +85,9 @@ const __typeof__(((type *)0)->member) *__mptr = (ptr); \ (type *)((char *)__mptr - offsetof(type, member)); }) +/* Calculate size of structure member. */ +#define member_size(type, member) (sizeof(((type *)0)->member)) + #ifndef __unused #define __unused __attribute__((unused)) #endif -- cgit v1.2.3