Skip to contentSkip to conversation

minor cleanup of type-checking for ptrlist.h

RFC PATCH New Alecs King 1 participant 1 message Dec 31, 2005 Sparse checker

lore
Share & tools
lore

Alecs King

author
#0 lore raw

RFC PATCH 1/1 minor cleanup of type-checking for ptrlist.h

DECLARE_PTR_LIST and friends are for 'Silly type-safety check'. The member (type *list[1]) of strust listname is never directly dereferenced or used except for CHECK_TYPE things. So why was it made an array of pointer instead of simply a pointer? IMHO, it gives no benefits but complicates things a bit. Or am i missing something?

This patch just change the array of pointer to a pointer.

dissect.c +3 -3
index 7a13ffa..be809f1 100644
@@ -14,7 +14,7 @@
 
 #define	DO_LIST(l__, p__, expr__)		\
 	do {					\
-		typeof(l__->list[0]) p__;	\
+		typeof(l__->list) p__;	\
 		FOR_EACH_PTR(l__, p__)		\
 			expr__;			\
 		END_FOR_EACH_PTR(p__);		\
@@ -22,8 +22,8 @@
 
 #define	DO_2_LIST(l1__,l2__, p1__,p2__, expr__)	\
 	do {					\
-		typeof(l1__->list[0]) p1__;	\
-		typeof(l2__->list[0]) p2__;	\
+		typeof(l1__->list) p1__;	\
+		typeof(l2__->list) p2__;	\
 		PREPARE_PTR_LIST(l1__, p1__);	\
 		FOR_EACH_PTR(l2__, p2__)	\
 			expr__;			\
ptrlist.h +4 -4
index b42a0ca..6f1a289 100644
@@ -11,10 +11,10 @@
 	(type *)((void *)(ptr) - offsetof(type, member))
 
 /* Silly type-safety check ;) */
-#define DECLARE_PTR_LIST(listname,type)	struct listname { type *list[1]; }
-#define CHECK_TYPE(head,ptr)		(void)(&(ptr) == &(head)->list[0])
-#define TYPEOF(head)			__typeof__(&(head)->list[0])
-#define VRFY_PTR_LIST(head)		(void)(sizeof((head)->list[0]))
+#define DECLARE_PTR_LIST(listname,type)	struct listname { type *list; }
+#define CHECK_TYPE(head,ptr)		(void)(&(ptr) == &(head)->list)
+#define TYPEOF(head)			__typeof__(&(head)->list)
+#define VRFY_PTR_LIST(head)		(void)(sizeof((head)->list))
 
 #define LIST_NODE_NR (29)
 
Signature · 1 line
Alecs King