Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Padding between char array/VLA in struct? Date: Mon, 02 Aug 2021 11:12:39 -0700 Organization: None to speak of Lines: 25 Message-ID: <87eebbaf6w.fsf@nosuchdomain.example.com> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="6d572ab74fff7e435a45dc17f7728aa8"; logging-data="26747"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/exGKY6NBECiJ5QFHjN1sG" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:sMqPit07FTa56XnYwMIbIxP/+EY= sha1:iniS76e1Y72k97K4d2UdoCUVFGE= Xref: csiph.com comp.lang.c:162198 Ian Pilcher writes: > Given the following: > > struct foo { > /* other members */ > char prefix[PREFIX_SIZE]; > char name[]; > }; > > Is there any circumstance in which the compiler is permitted to insert > padding between the 'prefix' and 'name' members? > > I'm 99% sure than the answer is no, but I've been unable to track down > the actual rules anywhere. I'm 99% sure the answer is "always". Compilers typically insert padding only when it's necessary to meet alignment requirements, but compilers are allowed to insert arbitrary padding between members. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips void Void(void) { Void(); } /* The recursive call of the void */