use __builtin_offsetof to implement offsetof when possible
authorRich Felker <dalias@aerifal.cx>
Wed, 5 Dec 2012 05:00:42 +0000 (00:00 -0500)
committerRich Felker <dalias@aerifal.cx>
Wed, 5 Dec 2012 05:00:42 +0000 (00:00 -0500)
apparently recent gcc versions have intentionally broken the
traditional definition by treating it as a non-constant expression.
the traditional definition may also be problematic for c++ programs.

include/stddef.h

index dbf5a4ae1fe987b9059fe2510171634c4db51bb6..a5bb9ecc2539cdfaec4226dc36d53d59f34cd027 100644 (file)
 
 #include <bits/alltypes.h>
 
+#if __GNUC__ > 3
+#define offsetof(type, member) __builtin_offsetof(type, member)
+#else
 #define offsetof(type, member) ((size_t)( (char *)&(((type *)0)->member) - (char *)0 ))
+#endif
 
 #endif