]> mj.ucw.cz Git - libucw.git/commitdiff
added macros CHECK_PTR_TYPE and PTR_TO
authorRobert Spalek <robert@ucw.cz>
Tue, 18 Apr 2006 12:26:59 +0000 (14:26 +0200)
committerRobert Spalek <robert@ucw.cz>
Tue, 18 Apr 2006 12:26:59 +0000 (14:26 +0200)
lib/lib.h

index 614b88c8e5d14cfb5d84e39476330bdd68ccbb2f..06a42ecec20fabae00dfab0915265c03787d8147 100644 (file)
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -3,6 +3,7 @@
  *
  *     (c) 1997--2006 Martin Mares <mj@ucw.cz>
  *     (c) 2005 Tomas Valla <tom@ucw.cz>
+ *     (c) 2006 Robert Spalek <robert@ucw.cz>
  *
  *     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))