Subject: Re: CVS commit: src/include
To: None <source-changes@NetBSD.org>
From: Joerg Sonnenberger <joerg@britannica.bec.de>
List: source-changes
Date: 08/21/2006 16:39:36
--Boundary_(ID_yJzMbWvpGsq16f1fbA/jKg)
Content-type: text/plain; charset=us-ascii
Content-transfer-encoding: 7BIT
Content-disposition: inline

On Mon, Aug 21, 2006 at 02:09:44PM +0000, Stephen Degler wrote:
> 
> Module Name:	src
> Committed By:	skd
> Date:		Mon Aug 21 14:09:44 UTC 2006
> 
> Modified Files:
> 	src/include: stddef.h
> 
> Log Message:
> Use gcc's builtin function.  This permits c++ compiliation of const
> expressions using offsetof.  Boost-python relies on this, for example.

This is absolutely wrong. The builtin is GCC specific. Even worse, it
only exist in pretty new revisions of GCC. Attached version is derived
from what I commited to DragonFly a while ago and much better. The C++
part is still a bit GCC specific, but that can't be entirely avoided.

Joerg

--Boundary_(ID_yJzMbWvpGsq16f1fbA/jKg)
Content-type: text/plain; charset=us-ascii; NAME=stddef.h.diff
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename=stddef.h.diff

Index: stddef.h
===================================================================
RCS file: /cvsroot/src/include/stddef.h,v
retrieving revision 1.11
diff -u -r1.11 stddef.h
--- stddef.h	21 Aug 2006 14:09:43 -0000	1.11
+++ stddef.h	21 Aug 2006 14:38:20 -0000
@@ -50,6 +50,15 @@
 
 #include <sys/null.h>
 
-#define	offsetof(type, member)	__builtin_offsetof(type,member)
+#if defined(__GNUC__) && (__GNUC__ >= 4)
+#define	offsetof(type, member)	__builtin_offsetof(type, member)
+#elif !defined(__cplusplus)
+#define	offsetof(type, member)	((size_t)(unsigned long)(&((type *)0)->member))
+#else
+#define	offsetof(type, member)					\
+	(__offsetof__ (reinterpret_cast <size_t>		\
+		 (&reinterpret_cast <const volatile char &>	\
+		  (static_cast<type *> (0)->member))))
+#endif  
 
 #endif /* _STDDEF_H_ */

--Boundary_(ID_yJzMbWvpGsq16f1fbA/jKg)--