From 4eddbcf2626b1394e1eb1a9c3928002bb346e178 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 11 Aug 2006 07:09:28 +0000 Subject: r7325@Kushana: nickm | 2006-08-10 23:37:31 -0700 Use gcc offsetof where available. svn:r7021 --- src/common/util.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/common/util.h') diff --git a/src/common/util.h b/src/common/util.h index 7c0cc1c5a..da5d31904 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -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 member within the type tp, 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" -- cgit v1.2.3