From 597c2f9b52230c15df49224c3a3a2f11288f5038 Mon Sep 17 00:00:00 2001 From: Robert Spalek Date: Tue, 18 Apr 2006 14:26:59 +0200 Subject: [PATCH] added macros CHECK_PTR_TYPE and PTR_TO --- lib/lib.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/lib.h b/lib/lib.h index 614b88c8..06a42ece 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -3,6 +3,7 @@ * * (c) 1997--2006 Martin Mares * (c) 2005 Tomas Valla + * (c) 2006 Robert Spalek * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -22,7 +23,9 @@ /* Ugly structure handling macros */ -#define OFFSETOF(s, i) ((unsigned int)&((s *)0)->i) +#define CHECK_PTR_TYPE(x, type) ((x)-(type)(x) + (type)(x)) +#define PTR_TO(s, i) &((s*)0)->i +#define OFFSETOF(s, i) ((unsigned int) PTR_TO(s, i)) #define SKIP_BACK(s, i, p) ((s *)((char *)p - OFFSETOF(s, i))) #define ALIGN(s, a) (((s)+a-1)&~(a-1)) #define ALIGN_PTR(p, s) ((addr_int_t)(p) % (s) ? (typeof(p))((addr_int_t)(p) + (s) - (addr_int_t)(p) % (s)) : (p)) -- 2.39.2