Re: [PATCH 1/1] container_of: Document container_of_const() is preferred
From: Greg Kroah-Hartman
Date: Tue Jun 18 2024 - 10:29:37 EST
On Tue, Jun 18, 2024 at 02:56:17PM +0100, Matthew Wilcox wrote:
> On Tue, Jun 18, 2024 at 02:54:53PM +0200, Greg Kroah-Hartman wrote:
> > > I didn't have any issues (apart from me misspelling function names ;)) with
> > > GCC 12, neither in using container_of_const() in a static inline function
> > > nor in using a static inline function as a _Generic() expression.
> >
> > Really? And how do you handle the pointer being either const or not,
> > and propagating that back out as the return type? I'd like to see your
> > inline function please.
>
> Here's how I did it for page_folio():
>
> #define page_folio(p) (_Generic((p), \
> const struct page *: (const struct folio *)_compound_head(p), \
> struct page *: (struct folio *)_compound_head(p)))
>
> Is there something differently magic about container_of() that prevents
> this trick from working?
That's a #define, not an inline function, which is what I thought we
were talking about.
thanks,
greg k-h