Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site mit-athena.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!mit-athena!jc From: jc@mit-athena.UUCP (John Chambers) Newsgroups: net.lang.c Subject: Re: Un-alignment in structures Message-ID: <120@mit-athena.UUCP> Date: Mon, 18-Mar-85 09:40:15 EST Article-I.D.: mit-athe.120 Posted: Mon Mar 18 09:40:15 1985 Date-Received: Thu, 21-Mar-85 02:30:21 EST References: <9239@brl-tgr.ARPA> Organization: MIT Project Athena Lines: 38 Once again we hahear a justification of C's alignment on the grounds that some machines can't load and store unaligned quantities. THIS IS NOT TRUE! Every machine I've ever used, and I suspect all that have ever been built, can do this quite easily. The method is simple. For unaligned loads, you write code that loads the containing words into two registers, use AND instructions to zero out the unwanted portions, SHIFT instructions to align the wanted bits properly, and an OR instruction to combine them. Every machine I've ever seen has LOAD, AND, SHIFT and OR instructions. But, but, but... This is inefficient, I hear people muttering. Well, sure it is, but it's not any more efficient when I have to code it myself because the @#$#%@# compiler refuses to do it for me. If the data is unaligned (as often happens when you are getting it from another machine), someone has to write the inefficient code to extract the data. It is either me or the compiler. This is not a difficult job for a compiler to do. I know, I've written several. Compilers were invented back in the 50's to save people time by making the machine do the drudge work in generating machine language. Handling misaligned data is an especially dreary piece of drudge work that is both hard for me and easy for the machine. Why can't compilers do their job (making life easy for programmers) right, rather than making feeble excuses that don't stand up to the slightest investigation? I'm getting sort of tired of writing the same pieces of stereotyped code over and over and over and over and over, when I know very well how easy it would be for the compiler to do it for me. (Well, sure, I could dig in and modify the compiler. I did this once. Then I moved to another machine, and its C compiler needed the change, too, and...) Grumble, grumble, grumble.... -- John Chambers [...!decvax!mit-athena] If you're not part of the solution, then you're part of the precipitate.