diff options
author | Neel Chauhan <neel@neelc.org> | 2017-07-31 19:30:30 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-08-03 08:56:35 -0400 |
commit | 5ee6ca8da22ad8da94c829e6c02c05920742c364 (patch) | |
tree | 4e69b0cc5f825f316aa05b290d2340c94e46c3ea /src/common/util.h | |
parent | 02fcb29d11abe9556ab4d118f2f89e557d1751dd (diff) | |
download | tor-5ee6ca8da22ad8da94c829e6c02c05920742c364.tar.gz tor-5ee6ca8da22ad8da94c829e6c02c05920742c364.zip |
Switch to offsetof()
Diffstat (limited to 'src/common/util.h')
-rw-r--r-- | src/common/util.h | 12 |
1 files changed, 2 insertions, 10 deletions
diff --git a/src/common/util.h b/src/common/util.h index d56abcee2e..df581d2405 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -109,19 +109,11 @@ extern int dmalloc_free(const char *file, const int line, void *pnt, void tor_log_mallinfo(int severity); -/** Return the offset of <b>member</b> within the type <b>tp</b>, in bytes */ -#if defined(__GNUC__) && __GNUC__ > 3 -#define STRUCT_OFFSET(tp, member) __builtin_offsetof(tp, member) -#else - #define STRUCT_OFFSET(tp, member) \ - ((off_t) (((char*)&((tp*)0)->member)-(char*)0)) -#endif - /** Macro: yield a pointer to the field at position <b>off</b> within the * structure <b>st</b>. Example: * <pre> * struct a { int foo; int bar; } x; - * off_t bar_offset = STRUCT_OFFSET(struct a, bar); + * off_t bar_offset = offsetof(struct a, bar); * int *bar_p = STRUCT_VAR_P(&x, bar_offset); * *bar_p = 3; * </pre> @@ -138,7 +130,7 @@ void tor_log_mallinfo(int severity); * </pre> */ #define SUBTYPE_P(p, subtype, basemember) \ - ((void*) ( ((char*)(p)) - STRUCT_OFFSET(subtype, basemember) )) + ((void*) ( ((char*)(p)) - offsetof(subtype, basemember) )) /* Logic */ /** Macro: true if two values have the same boolean value. */ |