Skip to contentSkip to conversation

container_of() doubt

PATCH Felipe Balbi 1 participant 2 messages Feb 27, 2013

lore
Share & tools
lore
#0 lore raw

Hi Greg,

hehe, you must've answered this over and over again, but I don't see the need for __mptr in the container_of() macro. I tried googling it but couldn't find much.

I get the macro, but not the need __mptr. Wouldn't this work the same way ?

include/linux/kernel.h +1 -2
index 80d3687..bbce857 100644
@@ -717,8 +717,7 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
  *
  */
 #define container_of(ptr, type, member) ({			\
-	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
-	(type *)( (char *)__mptr - offsetof(type,member) );})
+	(type *)( (char *)(ptr) - offsetof(type,member) );})
 
 /* Trap pasters of __FUNCTION__ at compile-time */
 #define __FUNCTION__ (__func__)

why do we need this type * NULL ?

thanks

Signature · 1 line
balbi
#1 lore raw

Hi again,

Quoted 24 lines · Felipe Balbi

Hi Greg,

hehe, you must've answered this over and over again, but I don't see the need for __mptr in the container_of() macro. I tried googling it but couldn't find much.

I get the macro, but not the need __mptr. Wouldn't this work the same way ?

include/linux/kernel.h +1 -2
index 80d3687..bbce857 100644
@@ -717,8 +717,7 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
  *
  */
 #define container_of(ptr, type, member) ({			\
-	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
-	(type *)( (char *)__mptr - offsetof(type,member) );})
+	(type *)( (char *)(ptr) - offsetof(type,member) );})
 
 /* Trap pasters of __FUNCTION__ at compile-time */
 #define __FUNCTION__ (__func__)
Quoted 1 line

why do we need this type * NULL ?

nevermind, type safety ;-)

Signature · 1 line
balbi