From: Olivier Houchard Date: Wed, 24 Jan 2018 17:17:06 +0000 (+0100) Subject: MINOR: compiler: introduce offsetoff(). X-Git-Tag: v1.9-dev1~452 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=928fbfa;p=thirdparty%2Fhaproxy.git MINOR: compiler: introduce offsetoff(). Add a offsetof() macro, if it is no there already. --- diff --git a/include/common/compiler.h b/include/common/compiler.h index a13aad5c62..125c473997 100644 --- a/include/common/compiler.h +++ b/include/common/compiler.h @@ -107,5 +107,23 @@ #endif #endif +#ifndef __GNUC_PREREQ__ +#if defined(__GNUC__) && !defined(__INTEL_COMPILER) +#define __GNUC_PREREQ__(ma, mi) \ + (__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi)) +#else +#define __GNUC_PREREQ__(ma, mi) 0 +#endif +#endif + +#ifndef offsetof +#if __GNUC_PREREQ__(4, 1) +#define offsetof(type, field) __builtin_offsetof(type, field) +#else +#define offsetof(type, field) \ + ((__size_t)(__uintptr_t)((const volatile void *)&((type *)0)->field)) +#endif +#endif + #endif /* _COMMON_COMPILER_H */