From: Junio C Hamano Date: Fri, 23 Sep 2022 22:04:10 GMT Subject: Re: [PATCH] read-cache: avoid misaligned reads in index v4 Message-ID: In-Reply-To: Jeff King writes: > Here (and elsewhere), you can assume that the offsetof() "sec" in > cache_time is 0, for two reasons: > > - I didn't look up chapter and verse, but I'm pretty sure the standard > does guarantee that the first field of a struct is at the beginning. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf 6.7.2.1 #13 (page 103) Within a structure object, the non-bit-field members and the units in which bit-fields reside have addresses that increase in the order in which they are declared. A pointer to a structure object, suitably converted, points to its initial member (or if that member is a bit-field, then to the unit in which it resides), and vice versa. There may be unnamed padding within a structure object, but not at its beginning. As an initial padding is forbidden, the first member's offset is zero.