Opened 16 years ago

Last modified 14 years ago

#207 closed defect

include/sys/cdefs.h needs updating for GCC 4.x — at Version 2

Reported by: psmedley Owned by: bird
Priority: normal Milestone: libc-0.6.4
Component: libc Version: 0.6.2
Severity: normal Keywords:
Cc:

Description (last modified by bird)

With the included cdefs.h, GCC 4.x breaks when building the JS code in mozilla with an error 'error: array bound is not an integer constant'

The problem comes from mozilla includes that use offsetof

cdefs.h needs to be updated for GCC 4.x, the following diff based on updated BSD headers fixes the problem:

--- u:\usr\include\sys\cdefs.h	2009-01-18 18:54:06.000000000 +0945
+++ u:\usr\local432\include\sys\cdefs.h	2009-01-18 18:55:24.000000000 +0945
@@ -251,9 +251,21 @@
  * We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h>
  * require it.
  */
-#define	__offsetof(type, field)	((size_t)(&((type *)0)->field))
-#define	__rangeof(type, start, end) \
-	(__offsetof(type, end) - __offsetof(type, start))
+#if __GNUC_PREREQ__(4, 1)
+#define __offsetof(type, field)  __builtin_offsetof(type, field)
+#else
+#ifndef __cplusplus
+#define __offsetof(type, field) ((size_t)(&((type *)0)->field))
+#else
+#define __offsetof(type, field)                                 \
+  (__offsetof__ (reinterpret_cast <size_t>                      \
+                 (&reinterpret_cast <const volatile char &>     \
+                  (static_cast<type *> (0)->field))))
+#endif
+#endif
+#define __rangeof(type, start, end) \
+         (__offsetof(type, end) - __offsetof(type, start))
+
 
 /*
  * Compiler-dependent macros to declare that functions take printf-like

Change History (3)

by psmedley, 16 years ago

Attachment: cdefs.h.diff added

cdefs.h diff

comment:1 by psmedley, 16 years ago

Diff got screwed up so added it as an attachment

comment:2 by bird, 14 years ago

Description: modified (diff)
Status: newassigned
Note: See TracTickets for help on using tickets.