Source-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/include



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
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_ */


Home | Main Index | Thread Index | Old Index