Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!sri-spam!sri-unix!hplabs!sdcrdcf!usc-oberon!blarson From: blarson@usc-oberon.UUCP (Bob Larson) Newsgroups: net.lang.c Subject: Re: Must casting destroy lvalueness? Message-ID: <256@usc-oberon.UUCP> Date: Sat, 25-Oct-86 09:15:44 EST Article-I.D.: usc-ober.256 Posted: Sat Oct 25 09:15:44 1986 Date-Received: Mon, 27-Oct-86 01:26:27 EST References: <4617@brl-smoke.ARPA> <657@dg_rtp.UUCP> <55@cartan.Berkeley.EDU> Reply-To: blarson@usc-oberon.UUCP (Bob Larson) Organization: USC Computing Services, Los Angeles, CA Lines: 46 Summary: YES In article <55@cartan.Berkeley.EDU> desj@brahms (David desJardins) writes: [some stuff so wrong that I decided to reply] >In article <4617@brl-smoke.ARPA>, NET-RELAY.ARPA>@brl-smoke.ARPA writes: >> For example, a useful and readable way to move a pointer >> through a buffer containing a mixture of objects of different sizes is >> >> ((OBJECT)pointer)++ Here is a major misconseption, based on a limited set of machines and a limited imagination: > But the point is that casts of pointers *don't* convert. Repeat until remembered: CASTS DO ANY NESSISARY CONVERSION. There are machines with more than one type of pointer. C makes no assuptions that require there only to be one type of pointer. "Byte" pointers on a PDP-10 include both the bit position and size of the object being pointed to. There are quite a few machines with different "word" and "character" pointers. To do what the original poster wanted (as portably as possible): (pointer = (type_of_pointer) ((char *)pointer + sizeof(OBJECT))) It says what you mean. It is no more ugly than what you are trying to do. The explicit casts are obvious places to look for portablility problems. [ If casts did not implicitly lose the lvalueness of the expression, can you tell me what the following code fragment should do? Please explain in terms the begining C programer who meant f += (float)i; could understand, as well as the non-portable C coder who means *(int *)&f = i; float f = 0.1; int i = 2; (int)f += i; ] -- Bob Larson Arpa: Blarson@Usc-Eclb.Arpa or blarson@usc-oberon.arpa Uucp: (ihnp4,hplabs,tektronix)!sdcrdcf!usc-oberon!blarson