Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!chinet!dag From: dag@chinet.UUCP (Daniel A. Glasser) Newsgroups: comp.lang.c Subject: Re: what C needs -- packed structures Message-ID: <2102@chinet.UUCP> Date: 12 Jan 88 15:59:11 GMT References: <8801071842.AA04669@decwrl.dec.com> <2083@chinet.UUCP> <3816@hoptoad.uucp> Reply-To: dag@chinet.UUCP (Daniel A. Glasser) Organization: Chinet - Public Access Unix Lines: 73 In article <3816@hoptoad.uucp> gnu@hoptoad.uucp (John Gilmore) writes: [Excerpts from an article I posted deleted] > >To me this looks like an argument *for* packed structures. Is the >author proposing that if we want to access data defined by an outside >constraint, we should write assembly language routines? I would >rather have the C compiler figure out the difference between the PDP-11 >assembler sequence and the 68000 sequence, thank you. Or how is he >proposing that we write "portable" definitions using macros and unions, >which are just as dependent as structs on compiler alignment, word size, >etc? Well, no, this was in oposition to packed structures being mandated by the standard. Different machine archetectures support different packing schemes. The requirements placed on the compiler code generation when packed structures are being used may be easy on one machine and very hard on another. I am willing to be convinced otherwise, but I would need to see a 68000 (not 68020) compiler that supports packed structures before I would be ready to rewrite the compilers that I work on to support these things. I do have a few questions for those who want packed structures: 1) must the packed "keyword" be in the structure definition or just with the declaration? ie: packed struct rowdy { char r_y; int r_i; struct rowdy *r_next; }; struct rowdy wow; vs. struct rowdy { char r_y; int r_i; struct rowdy *r_next; }; packed struct rowdy wow; struct rowdy why; The second is more 'C' like, but really screws up what r_i and r_next might mean in a given context, let alone what happens if you say "why = wow". 2) There is this "prior-art" thing. Yes, some compilers give you switches to select which way you want structures packed, but this is not a semantic change to the language, and god have mercy on the soul of the programmer who mixes modules compiled with different packing strategies. Yes, Pascal also provides packed types; C is not Pascal. Have you ever encountered a C compiler for an archetecture that does impose alignment restrictions on multi-byte simple types (not just a performance penalty, ala 808[86]) that provides packed structures? I have not, and I've seen lots of compilers. If you want to have packed structures in C, find a vendor who is willing to provide them or write an implementation yourself, make sure the extension is clean and does not violate too many C conventions and see that the rest of the world gets to see this extension and it becomes popular. Then participate in the continuing ANSI C committee and see that this extension makes it into the next standard. ANSI does not disallow a compiler from providing extensions. Extensions are just not portable, and should be disableable. -- Daniel A. Glasser ...!ihnp4!chinet!dag ...!ihnp4!mwc!dag ...!ihnp4!mwc!gorgon!dag One of those things that goes "BUMP!!! (ouch!)" in the night.