Skip to content

Instantly share code, notes, and snippets.

@aji
Created October 12, 2012 19:23
Show Gist options
  • Select an option

  • Save aji/3880975 to your computer and use it in GitHub Desktop.

Select an option

Save aji/3880975 to your computer and use it in GitHub Desktop.
struct foo {
int data1;
char *data2;
mytype_t mymember;
int data3;
};
...
struct foo blah;
mytype_t *var = &(blah.mymember);
container_of(var, struct foo, mymember); /* returns pointer to blah */
...
/* more "practical" example of how this is used in the wild. pretend
somefunc returns a mytype_t pointer */
struct foo *blah = container_of(somefunc(), struct foo, mymember);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment