RISC Machine Data Structure Word Alignment Problems?
carl weidling
carlw at mercury.sybase.com
Sat Feb 3 03:53:42 AEST 1990
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 at utzoo.uucp> henry at 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
More information about the Comp.lang.c
mailing list