Re: [PATCH] overflow: Introduce struct_offset() to get offset of member

Steven Rostedt
2025-11-28T17:19:24Z

On Thu, 27 Nov 2025 21:35:35 -0800
Linus Torvalds <torvalds@linux-foundation.org> wrote:

> So that 'xyz_t()' version then gets used for things where you
> explicitly state the type, and it all looks fairly obvious, eg:
>
> len = struct_size_t(struct pid, numbers, level + 1);
>
> doesn't get that "WHAA?!??!" kind of reaction.
>
> [ And so I actually think it's good that it only takes an explicit
> type - if you really have an instance, I think it's better to use just
> "struct_size(&instance, ...)" even if we _could_ easily make syntax
> like "struct_size_t(instance, ...)" work. ]

I was thinking about adding a struct_offset_t() but then I noticed that
struct_size_t() requires adding the type as it is for just getting the
size of the struct without using a variable. Whereas, I would have
preferred the struct_offset_t() to use a variable that's not a pointer
where typeof() is used.

But for my use cases, I can just add a '&' to struct_offset(), as if
struct_offset_t() were to take a type, it is no different than
offsetof().

-- Steve