DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 1/2] Fix container_of() macro to work with const members
@ 2017-02-14 14:36 Jan Blunck
  2017-02-14 14:36 ` [dpdk-dev] [PATCH 2/2] Ensure constness of target pointer type Jan Blunck
  2017-02-27 14:28 ` [dpdk-dev] [PATCH 1/2] Fix container_of() macro to work with const members Jan Blunck
  0 siblings, 2 replies; 5+ messages in thread
From: Jan Blunck @ 2017-02-14 14:36 UTC (permalink / raw)
  To: dev

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@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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-03-08 14:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-14 14:36 [dpdk-dev] [PATCH 1/2] Fix container_of() macro to work with const members Jan Blunck
2017-02-14 14:36 ` [dpdk-dev] [PATCH 2/2] Ensure constness of target pointer type Jan Blunck
2017-02-27 14:28 ` [dpdk-dev] [PATCH 1/2] Fix container_of() macro to work with const members Jan Blunck
2017-02-27 15:14   ` Bruce Richardson
2017-03-08 14:01     ` Thomas Monjalon

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git