Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.stack.nl!aioe.org!.POSTED!not-for-mail From: Walter Banks Newsgroups: comp.std.c Subject: Re: Structure Packing. Date: Tue, 12 Jun 2012 17:17:50 -0400 Organization: Aioe.org NNTP Server Lines: 35 Message-ID: <4FD7B1FE.7BE5D0E@bytecraft.com> References: <12b3df42-f6a0-4411-a5e5-136900f8255b@googlegroups.com> <4FD6ABFA.72F52C75@bytecraft.com> <4FD79758.38D5CBF0@bytecraft.com> NNTP-Posting-Host: uMDnRznCaHm25BLlk25agA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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:1374 Eric Sosman wrote: > > > That would make me uncomfortable, too. Remember, it's always > allowed to convert a pointer to a struct to a pointer to its first > element and vice versa, and if your compiler rearranges the element > order this could break rather badly. Think of all those linked > lists where the "next" pointer is assumed to be the first thing in > the struct (so "generic" functions can find it), and think of the > havoc that could ensue if the compiler silently shuffled a "double" > into first place in the name of storage efficiency ... The first element is never going to be a problem in this case. One of the very few really good things is that I will never need to pad the first element. It can for example be either a char or int and in every case be referenced by it actual first element address. > One thing you might consider would be to have your compiler > emit a warning message for inefficiently-arranged structs. (The > compiler is always permitted to whine, even about perfectly legal > code.) This would draw people's attention to wasteful constructs > without breaking C conformance. I am coming to that conclusion. Even better it is reasonably easy for the compiler to define a cleaner declaration and make the whining helpful. Thanks w..