# How the Linux Kernel's container\_of() Macro Works

DevFeed: [How the Linux Kernel's container\_of() Macro Works](<https://devfeed.tech/articles/the-magical-container-of-macro-40712.md>)

Original publisher: [Read original article](<https://radek.io/posts/magical-container_of-macro/>)

Published: 2012-11-10T00:00:00Z

Content type: article

Language: en

Sources: [Radek Pazdera](<https://devfeed.tech/sources/radek-pazdera.md>)

Topics: [C](<https://devfeed.tech/topics/c.md>), [Linux Kernel](<https://devfeed.tech/topics/linux-kernel.md>), [container](<https://devfeed.tech/topics/container.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [standard](<https://devfeed.tech/topics/standard.md>)

Tags: [c](<https://devfeed.tech/tags/c.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [container](<https://devfeed.tech/tags/container.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [library](<https://devfeed.tech/tags/library.md>), [linux-kernel](<https://devfeed.tech/tags/linux-kernel.md>), [standard](<https://devfeed.tech/tags/standard.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>), [value](<https://devfeed.tech/tags/value.md>)

## AI overview

This tutorial explains how the Linux Kernel's container_of() macro derives a pointer to a containing structure from a pointer to one of its members. It describes GNU C extensions, including braced groups within expressions and typeof(), and explains the zero-pointer dereference and member-offset techniques used in the implementation.

## Source excerpt

Probably the most confusing piece of C code I've encountered