Re: [PATCH 0/3] Add offsetofp() and offsetofendp() for pointer arithmetic

From: Bence Csókás

Date: Fri Nov 06 2026 - 03:38:37 EST


Hi,

On 2026. 11. 06. 9:04, Christoph Hellwig wrote:
On Thu, Nov 05, 2026 at 06:16:15PM +0100, Bence Csokas wrote:
A common usage pattern for offsetof() is the following:

offsetof(typeof(*ptr), member)

Condense this operation to one macro for a more maintainable code base.

What exactly makes non-standard macros with no obvious safety benefit
more maintainable?

It is written out in more detail in the msg of 1/3: it helps keep lines short, and as typeof(*ptr) may not come naturally to many, some may be compelled to write out the typename twice::

struct my_struct_type *p;
off = offsetof(struct my_struct_type, member);
// pointer arithmetic with p and off

which induces additional work if *p's type changes.

However, as Sashiko pointed out (don't know why it didn't write this earlier), struct_offset() already exists, so we should just use that one, and probably add a struct_offset_end() variant.

Sorry for the noise, everyone.

Bence