container_of_const(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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