Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP Path: utzoo!utcsri!greg From: greg@utcsri.UUCP (Gregory Smith) Newsgroups: net.lang.c Subject: Re: Phooey on Portability Message-ID: <3604@utcsri.UUCP> Date: Thu, 6-Nov-86 23:58:07 EST Article-I.D.: utcsri.3604 Posted: Thu Nov 6 23:58:07 1986 Date-Received: Fri, 7-Nov-86 17:20:45 EST References: <5225@brl-smoke.ARPA> Reply-To: greg@utcsri.UUCP (Gregory Smith) Organization: CSRI, University of Toronto Lines: 68 Summary: Phooey on you In article <5225@brl-smoke.ARPA> T-RELAY.ARPA>@brl-smoke.ARPA writes: >I'd like to get at the byte stored in memory location 6. So I just > >struct { > char byte; > int word; > long longword; >} *MEMORY; > >main(){char mybyte = 6->byte;} > >No sweat. Works like a charm daily. wrong, Wrong, WRONG! I won't try to correct the weirdnesses above since I can't really see what you're doing. What are 'word' and 'longword' for ??? It's done like this: mybyte = * ( char * ) 6; > But what do I do on segmented memory >systems like the PC? > >main(){char mybyte = 0:6->byte;} Easy. *( char * ) 6. On a hideous machine like the 8088, (char *)6 *should* yield a pointer to the absolute address 6, in whatever pointer format is used in the 'memory model'(barf) you are using. Thus *(char *)6 *should* be an lvalue which is stored at that absolute address. Whether this happens or not is up to whichever masochist wrote the compiler. > >So much of the squirming about lvalues and chars and the like >comes from both wanting to be memory system independent and close the metal. >Why don't we just say that every compiler writer should include a section >in the manual called "Memory Model" wherein the following things are defined? Yes. This section should list the things that *will* work on that implementation, but which you shouldn't use ( unless you are writing device drivers ) because they won't port. It should then give you equivalent portable methods. >I personally want to snuggie right up the memory system in my C programs. Do you want to play with segment registers in your C code ( shudder )? >That's why I chose C! I really have plenty to worry about besides machines >I'm NOT trying to program. I guess what I'm saying is that until we can >create well-engineered, reliable code for one machine why are we wasting >our time worrrying about doing it for all machines at once? Because it's not that much harder, once you get used to it. Who says we can't create reliable, well-engineered code? I have. It takes less *extra* time to make something portable than it takes to go through and hack it up if you do have to port it. It does happen. >In other words, >portability is mostly a red herring. Good code on one machine beats >bad code on many machines every time. > Great! so why not write good code which is portable? It is mostly the 'messy' stuff that causes portability problems anyway. -- ---------------------------------------------------------------------- Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg Have vAX, will hack...