carlw@mercury.sybase.com (carl weidling) (02/03/90)
The question is whether or not C's requirement to build structures with the components in the order in which they were declared is a mistake or not. In article <1990Jan29.173412.2859@utzoo.uucp> henry@utzoo.uucp (Henry Spencer) writes: < stuff deleted > >The basic problem here is that the compiler cannot read minds, and the >language does not provide a way to tell the compiler which of two >interpretations is wanted. The two possibilities are "I want precise >control of what goes into memory" and "I want these members but please >pad as necessary to make accesses fast". Unfortunately, you can't just >say "well, if I want padding I'll put it in myself", because many people >want to write portable programs, and the padding requirements are *very* >machine-specific. Precise control of memory layout is not necessary for < rest of article deleted> Reading this I got an idea which is a slight variation on the idea of a pragma or directive in the language. Why not have a PRE-processor directive that will re-arrange the fields in a structure to maximize efficiency one way or the other? The C-language itself is untouched, the programmer can run the pre-processor by itself on the code to see what was done. Perhaps lint could be made smart enough to tell if someone was playing too many games with one of these re-arranged structures. Something like struct { int alpha; #ARRANGE_ANY_WAY_YOU_WANT /* maybe specify criteria? i.e. speed vs compact */ long beta; char gamma[3]; #END_ARRANGE } -Carl Weidling
shap@delrey.sgi.com (Jonathan Shapiro) (02/04/90)
In article <8314@sybase.sybase.com> carlw@mercury.UUCP (carl weidling) writes: > Why not have a PRE-processor directive that will re-arrange the >fields in a structure to maximize efficiency one way or the other? Yuck. If this problem is worth solving, it is worth solving right. Jon
carr@gandalf.UUCP (Dave Carr) (02/06/90)
In article <11666@thorin.cs.unc.edu>, tuck@jason.cs.unc.edu (Russ Tuck) writes: > > If the compiler did what you suggest and did not align struct members, > it would in most cases be impossible to access the data member "c" above > without causing the program to dump core. This would not be a useful > compiler "feature" :-). SPARC (and most other RISC archs) requires all > ordinary memory accesses to be aligned. That's *most* RISC architecture. At least with the 80960 (I know, not a true RISC), I have the freedom to access non word aligned data. I would rather have the choice than let the RISC architecture force me. Data explosion on RISC computers is pretty bad. We should have the choice between slowing the CPU down only for those accesses which are not word aligned. We could pad the structures to speed it back up. -- Dave Carr | carr@e.gandalf.ca | If you don't know where Gandalf Data Limited | TEL (613) 723-6500 | you are going, you will Nepean, Ontario, Canada | FAX (613) 226-1717 | never get there.