Skip to content

container_of: Fail compilation when void * is used as the member_ptr#70

Open
jgunthorpe wants to merge 1 commit intorustyrussell:masterfrom
jgunthorpe:void_container_of
Open

container_of: Fail compilation when void * is used as the member_ptr#70
jgunthorpe wants to merge 1 commit intorustyrussell:masterfrom
jgunthorpe:void_container_of

Conversation

@jgunthorpe
Copy link
Copy Markdown

This is actually a check_types_match problem, as

   check_types_match(*(void *)0, (int)0)

Will succeed because C allows 'void *' to compare against any other pointer. The solution is the same as typecheck.h uses in the kernel: add another pointer '*' to the type.

However, this means

  check_types_match(*(const int *)0, (int)0)

Will start failing as the implicit elimination of const is gone. This is actually used by a few container_of users in ccan, and seems desirable.

Use a simple solution to constify both sides before adding the extra pointer '*'.

Add tests to show that all of these above scenarios work.

This is actually a check_types_match problem, as
   check_types_match(*(void *)0, (int)0)

Will succeed because C allows 'void *' to compare against any other
pointer. The solution is the same as typecheck.h uses in the kernel:
add another pointer '*' to the type.

However, this means
  check_types_match(*(const int *)0, (int)0)

Will start failing as the implicit elimination of const is gone. This
is actually used by a few container_of users in ccan, and seems desirable.

Use a simple solution to constify both sides before adding the extra
pointer '*'.

Add tests to show that all of these above scenarios work.

Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant