the one and only objection to C
Ken Yap
ken at rochester.UUCP
Thu Jan 3 20:03:41 AEST 1985
It seems that my respondents picked on parts of my posting that they
did not agree with. I was trying to point out something more
interesting. Let me try again.
* As currently defined, or by the weight of existing programs, structs
have ordered fields but may have holes in them. This seems to me both
lax and restrictive. Lax because alignment is not specified and makes
device registers descriptions (for example) compiler-dependent.
Restrictive because a lot of programs do not care if the fields are not
allocated in the same order as they were declared.
* I do not seriously believe in putting an offset declaration feature
in C now. The syntax will probably be ugly and it is too radical a
change.
* The points I was trying to make are these:
(1) By removing the ordering requirement, the compiler has more room to
optimize. (Another optimization: compilers could put the more
frequently used fields nearer the front and use shorter offsets in
machine code.) Tell me if I am wrong, but Pascal can already do this
because the language does not guarantee field ordering in records.
(2) By giving the programmer a facility to control ordering/alignment
for those times when he cares, the code tells the compiler that
alignment must be preserved even at the expense of speed. The answer
for people who want to read binary files, write ANSI headers, describe
devices, do obscene things with data structures, et cetera.
* Surely this is the best of both worlds and worth considering in any
new language design? That is what I wanted to say.
I know this is a contentious newsgroup and I sometimes don't say what I
mean very well (I am tempted to rewrite the above). How about some
comments if you think it worth your while commenting on, instead of
making net.lang.c a religious battlefield. I really should have added a
:-) after the "flame away" in my last posting.
--
Ken Yap
UUCP: (..!{allegra, decvax, seismo}!rochester!ken) ARPA: ken at rochester.arpa
USnail: Dept. of Comp. Sci., U. of Rochester, NY 14627. Voice: Ken!
More information about the Comp.lang.c
mailing list