Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 (Tek) 9/26/83; site hammer.UUCP Path: utzoo!linus!decvax!tektronix!orca!hammer!steveg From: steveg@hammer.UUCP (Steve Glaser) Newsgroups: net.lang.c Subject: Re: limitations of casts, pointer and function declarartions... Message-ID: <991@hammer.UUCP> Date: Fri, 2-Nov-84 12:28:02 EST Article-I.D.: hammer.991 Posted: Fri Nov 2 12:28:02 1984 Date-Received: Sat, 3-Nov-84 21:48:05 EST References: <120@harvard.ARPA> Reply-To: steveg@hammer.UUCP (Steve Glaser) Organization: Tektronix, Wilsonville OR Lines: 32 Summary: In article guido@mcvax.UUCP (Guido van Rossum) writes: >In article <120@harvard.ARPA> breuel@harvard.ARPA (Thomas M. Breuel) writes: >> int x; >> char *y; >>/*### [cc] illegal lhs of assignment operator = %%%*/ >> (char *)x = y; > >Sorry, you're thinking Algol-68. What you need is: > *( (char*) &x ) = y; > Mostly right except that what I think Tom wanted was more like: *( (char**) &x ) = y; The same arguments you made still hold. Note that this is highly unportable code since it assumes that the bit layout in memory is compatable between ints and char *. There is nothing in the language that requires this. The only requirement in C is that converting a pointer to a suitably long int and back must not loose information. From what I've seen on net.lang.c, I think the Prime compiler may have this problem (48 bit pointers, 32 bit ints, when converting a pointer to an int the ring number portion of the pointer gets droped, when going the other way the ring number gets set to "user ring", works fine until you try to use it in non-user-ring code). Thus, the most portable way to write this expression is still: x = (int)y; Steve Glaser tektronix!steveg