Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Rainer Weikusat Newsgroups: de.comp.lang.c Subject: Re: Padding von Strukturen Date: Tue, 30 Jan 2024 16:06:20 +0000 Lines: 44 Message-ID: <87v87ast4z.fsf@doppelsaurus.mobileactivedefense.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net 4X2AIFV499pLFGcNG0bgjgtTBiTYXAcok3Jmkk+radJAoDkxU= Cancel-Lock: sha1:hIxyWXm/XiAOVX7zX3mVe3bmMsE= sha1:NQBcjP9EO3jjX6ZxjFEh6IL0kVg= sha256:FcRoRde57QAWZBLLCRgAk4aPt7klw3vjVSgd5aP+fSM= User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) Xref: csiph.com de.comp.lang.c:10586 Michael Bäuerle writes: [...] > | 6.5.6 Additive operators > | > | 8 [...] When an expression that has integer type is added to or > | subtracted from a pointer, [...] > | If the pointer operand points to an element of an array object, and > | the array is large enough, the result points to an element offset from > | the original element such that the difference of the subscripts of the > | resulting and original array elements equals the integer expression. > > Da steht nicht, dass der Offset ein Vielfaches der Größe der Elemente > (entsprechend dem was sizeof liefert) sein muss. Ist er ja auch nicht. Wie kommt man denn um Himmels Willen auf so eine vollkommen groteske Idee? ----- #include struct salami { char *nirgendwo; int irgendwas[2]; }; static struct salami spd[5]; int main(void) { struct salami *daresalami; daresalami = spd + 3; printf("Offset %zd, Elementgroesse %zd\n", daresalami - spd, sizeof(*spd)); return 0; } ---- Gibt für mich Offset 3, Elementgroesse 16 aus. Das drei kein Vielfaches von 16 ist, sollte klar sein.