From 55937c177f90ecf0dea40c318d2f8d52fa69b55d Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Fri, 20 Jan 2017 10:55:26 +0100 Subject: Implement offsetof via builtin. The implementation of offsetof as macro in the form ((size_t) &((ty*) NULL)->member) has the problem that it cannot be used everywhere were an integer constant expression is allowed, for example in initiliazers of global variables and there is also no check for the case that member is of bitifield type. The new implementation adds a builtin function for this which is replaced by an integer constant during elaboration. Bug 20765 --- runtime/include/stddef.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/include') diff --git a/runtime/include/stddef.h b/runtime/include/stddef.h index 5bdff564..452497c3 100644 --- a/runtime/include/stddef.h +++ b/runtime/include/stddef.h @@ -114,7 +114,7 @@ typedef signed int wchar_t; #endif #if defined(_STDDEF_H) && !defined(offsetof) -#define offsetof(ty,member) ((size_t) &((ty*) NULL)->member) +#define offsetof(ty,member) (__builtin_offsetof(ty,member)) #endif #endif -- cgit