From: Timo Sirainen Date: Thu, 30 Jan 2003 17:51:32 +0000 (+0200) Subject: Removed STRUCT_OFFSET, offsetof() is ANSI-C for the same purpose. Added X-Git-Tag: 1.1.alpha1~5054 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c856e87cf8e535c3ecf351fa28d7553c7ca9994a;p=thirdparty%2Fdovecot%2Fcore.git Removed STRUCT_OFFSET, offsetof() is ANSI-C for the same purpose. Added MEMBER() macro to define C99-style struct labels. --HG-- branch : HEAD --- diff --git a/src/lib/macros.h b/src/lib/macros.h index b350ca7f04..78defb1c7d 100644 --- a/src/lib/macros.h +++ b/src/lib/macros.h @@ -57,12 +57,10 @@ /* Provide convenience macros for handling structure * fields through their offsets. */ -#define STRUCT_OFFSET(struct_p, member) \ - ((long) ((char *) &((struct_p)->member) - (char *) (struct_p))) #define STRUCT_MEMBER_P(struct_p, struct_offset) \ - ((void *) ((char *) (struct_p) + (long) (struct_offset))) + ((void *) ((char *) (struct_p) + (long) (struct_offset))) #define STRUCT_MEMBER(member_type, struct_p, struct_offset) \ - (*(member_type *) G_STRUCT_MEMBER_P((struct_p), (struct_offset))) + (*(member_type *) G_STRUCT_MEMBER_P((struct_p), (struct_offset))) /* Provide simple macro statement wrappers (adapted from Perl): STMT_START { statements; } STMT_END; @@ -106,6 +104,13 @@ # define __attr_unused__ #endif +/* C99-style struct member definitions */ +#if (defined(__STDC__) && __STDC_VERSION__ >= 199901L) || __GNUC__ > 2 +# define MEMBER(name) .name = +#else +# define MEMBER(name) +#endif + /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with macros, so we can refer to them as strings unconditionally. */ #ifdef __GNUC__