container_of_const(9)
π container_of_const(9) π
okay so bestie, welcome to the Kernel API Manual β this is the page for container_of_const, and honestly? it's giving main character energy in the macro world. β¨
πΈ NAME πΈ
container_of_const β cast a member of a structure out to the containing structure and preserve the const-ness of the pointer π«Ά
like, it does the glow-up in reverse: you hand it a pointer to a member, and it hands you back the whole struct that member is embedded in β and it keeps the const-ness of your pointer intact. no cap. π
π SYNOPSIS π
container_of_const (ptr , type , member );
that's it, that's the whole vibe. three little args and you're slaying. π
β¨ ARGUMENTS β¨
ptrβ the pointer to the member. this is your starting point, your little entryway into the struct. πͺtypeβ the type of the container struct this is embedded in. yes, the whole struct, the big one, the one that's really doing the most. πmemberβ the name of the member within the struct. the specific little field you're pointing at. π―
π DESCRIPTION π
Always prefer container_of_const instead of container_of in new code.
fr fr. if you're writing new code, this is the one you reach for. container_of is lowkey old news for fresh code β container_of_const is the icon, the moment, the one that actually respects your const. π₯
π¦ SEE ALSO π¦
- Kernel file
./include/linux/container_of.hβ go read it, it's literally right there and it ate π container_of(9)β the classic, the OG, the one you're not preferring in new code π
ngl bestie, if you take one thing from this page: new code β container_of_const. every time. periodt. π
and that's the whole page!! π§ brought to you with love from the ./include/linux era, dated October 2026 β mwah, go write some const-correct macros, you absolute queen ππ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms