Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jgunthorpe
Copy link

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 <[email protected]>
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