[dpdk-dev] [PATCH 1/2] Fix container_of() macro to work with const members
Jan Blunck
jblunck at infradead.org
Tue Feb 14 15:36:05 CET 2017
This fixes the usage of structure members that are declared const to get
a pointer to the embedding parent structure.
Signed-off-by: Jan Blunck <jblunck at infradead.org>
---
lib/librte_eal/common/include/rte_common.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index 8dda3e2..c421708 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -347,8 +347,9 @@ rte_bsf32(uint32_t v)
*/
#ifndef container_of
#define container_of(ptr, type, member) __extension__ ({ \
- typeof(((type *)0)->member) *_ptr = (ptr); \
- (type *)(((char *)_ptr) - offsetof(type, member)); })
+ const typeof(((type *)0)->member) *_ptr = (ptr); \
+ (type *)(((uintptr_t)_ptr) - offsetof(type, member)); \
+ })
#endif
#define _RTE_STR(x) #x
--
2.7.4
More information about the dev
mailing list