Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Walter Banks Newsgroups: comp.std.c Subject: Re: Structure Packing. Date: Tue, 12 Jun 2012 15:06:16 -0400 Organization: Aioe.org NNTP Server Lines: 48 Message-ID: <4FD79328.A040F7B8@bytecraft.com> References: <12b3df42-f6a0-4411-a5e5-136900f8255b@googlegroups.com> <4FD6ABFA.72F52C75@bytecraft.com> <4FD7659E.89172310@bytecraft.com> NNTP-Posting-Host: pYfNRVqDKlDwIHKbefPq2Q.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org X-Mailer: Mozilla 4.79 [en]C-CCK-MCD NSCPCD479 (Windows NT 5.0; U) X-Accept-Language: en X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.std.c:1370 Hans-Bernhard Bröker wrote: > On 12.06.2012 17:51, Walter Banks wrote: > > > I have resolved every issue in this specific processor except memcpy > > and memcmp both of which are rarely used in embedded systems. > > I rather doubt the correctness of that assessment. And even if it were > correct, "rarely used" would not help you --- you would need "never > used". For tricks like the one you're considering to be viable, you > would have to intercept not just every call of memcpy(), but worse, > every single one of the roll-your-own implementations of it hidden > somewhere in the code --- including those that aren't even written in C > to begin with. Danger, Will Robinson! That isn't going to happen the memcpy and memcmp related issues would be a show stopper. > > I am uncomfortable even with packing the struct elements out of > > order. > > You should be more than uncomfortable --- that's actually disallowed by > the standard. To quote C99 6.7.2.1#16: > > 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. I represented Canada at ISO working on C99 and am aware of the wording and know the reasons. It is the reason I am so uncomfortable. We have never done it and this is a case where a struct empty space sometime exceeds the amount of ram space used. Arrays of structs are a disaster in some cases. Something that I just thought of that might work is to add an create an information message as part of the listing summary that identifies teh struct and a better data order declaration. The hardware in this case is imposing the constraints. The current implementation allocates next fit for each structure element. As the day goes on I am getting convinced that it is a bad idea. Walter Banks