Print this page
3373 gcc >= 4.5 concerns about offsetof()
Portions contributed by: Igor Pashev <pashev.igor@gmail.com>


  63 #if defined(_LP64) || defined(_I32LPx)
  64 typedef long    ptrdiff_t;              /* pointer difference */
  65 #else
  66 typedef int     ptrdiff_t;              /* (historical version) */
  67 #endif
  68 #endif  /* !_PTRDIFF_T */
  69 
  70 #if !defined(_SIZE_T) || __cplusplus >= 199711L
  71 #define _SIZE_T
  72 #if defined(_LP64) || defined(_I32LPx)
  73 typedef unsigned long   size_t;         /* size of something in bytes */
  74 #else
  75 typedef unsigned int    size_t;         /* (historical version) */
  76 #endif
  77 #endif  /* !_SIZE_T */
  78 
  79 #if __cplusplus >= 199711L
  80 }
  81 #endif /* end of namespace std */
  82 



  83 #if __cplusplus >= 199711L
  84 #define offsetof(s, m)  (std::size_t)(&(((s *)0)->m))
  85 #else
  86 #define offsetof(s, m)  (size_t)(&(((s *)0)->m))
  87 #endif

  88 
  89 #ifdef  __cplusplus
  90 }
  91 #endif
  92 
  93 #endif  /* _ISO_STDDEF_ISO_H */


  63 #if defined(_LP64) || defined(_I32LPx)
  64 typedef long    ptrdiff_t;              /* pointer difference */
  65 #else
  66 typedef int     ptrdiff_t;              /* (historical version) */
  67 #endif
  68 #endif  /* !_PTRDIFF_T */
  69 
  70 #if !defined(_SIZE_T) || __cplusplus >= 199711L
  71 #define _SIZE_T
  72 #if defined(_LP64) || defined(_I32LPx)
  73 typedef unsigned long   size_t;         /* size of something in bytes */
  74 #else
  75 typedef unsigned int    size_t;         /* (historical version) */
  76 #endif
  77 #endif  /* !_SIZE_T */
  78 
  79 #if __cplusplus >= 199711L
  80 }
  81 #endif /* end of namespace std */
  82 
  83 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
  84 #define offsetof(s, m) __builtin_offsetof(s, m)
  85 #else
  86 #if __cplusplus >= 199711L
  87 #define offsetof(s, m)  (std::size_t)(&(((s *)0)->m))
  88 #else
  89 #define offsetof(s, m)  (size_t)(&(((s *)0)->m))
  90 #endif
  91 #endif  /* GNUC, etc. */
  92 
  93 #ifdef  __cplusplus
  94 }
  95 #endif
  96 
  97 #endif  /* _ISO_STDDEF_ISO_H */