]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
r7325@Kushana: nickm | 2006-08-10 23:37:31 -0700
authorNick Mathewson <nickm@torproject.org>
Fri, 11 Aug 2006 07:09:28 +0000 (07:09 +0000)
committerNick Mathewson <nickm@torproject.org>
Fri, 11 Aug 2006 07:09:28 +0000 (07:09 +0000)
 Use gcc offsetof where available.

svn:r7021

src/common/util.h

index 7c0cc1c5a1d5f6f834d84427b9d1b42998f59e5e..da5d31904504e345d57d8f6b6fa9487c766260b4 100644 (file)
@@ -91,8 +91,12 @@ extern int dmalloc_free(const char *file, const int line, void *pnt,
 #define tor_memdup(s, n)       _tor_memdup(s, n DMALLOC_ARGS)
 
 /** Return the offset of <b>member</b> within the type <b>tp</b>, in bytes */
-#define STRUCT_OFFSET(tp, member) \
-  ((off_t) (((char*)&((tp*)0)->member)-(char*)0))
+#ifdef __GNUC__
+#define STRUCT_OFFSET(tp, member) __builtin_offsetof(tp, member)
+#else
+ #define STRUCT_OFFSET(tp, member) \
+   ((off_t) (((char*)&((tp*)0)->member)-(char*)0))
+#endif
 
 /* String manipulation */
 #define HEX_CHARACTERS "0123456789ABCDEFabcdef"