Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site bbncca.ARPA Path: utzoo!watmath!clyde!burl!mgnetp!ihnp4!bbncca!keesan From: keesan@bbncca.ARPA (Morris Keesan) Newsgroups: net.lang.c Subject: pointer -> long conversion Message-ID: <831@bbncca.ARPA> Date: Mon, 9-Jul-84 15:37:13 EDT Article-I.D.: bbncca.831 Posted: Mon Jul 9 15:37:13 1984 Date-Received: Tue, 10-Jul-84 02:30:12 EDT Organization: Bolt, Beranek and Newman, Cambridge, Ma. Lines: 23 ---------------------- On machines where pointers are shorter than longs, should the pointer sign-extend when being converted to long (assume all pointers the same size for simplicity -- on machines with more than one size of pointer, the question applies to those types of pointers which are shorter than longs)? This question arises because of some code we came across which is converting pointers to long in various ways (don't ask why -- it's a long story, but the reasons turn out to be mostly valid), and the compiled code is generating sign-extension. At first, this appears to be wrong, but on second thought I'm not sure. K&R says (section 7.14, p.192) "The compilers currently allow a pointer to be assigned to an integer, an integer to a pointer, and a pointer to a pointer of another type. The assignment is a pure copy operation, with no conversion." But what does "pure copy" mean, when the objects are of different sizes? Is there any reason to prefer non-sign-extension over sign-extension, or vice-versa? Is there any reason why a C programmer should legitimately care whether sign-extension occurs in these cases? Please no flames about whether converting pointers to longs is a reasonable operation. I'm just trying to figure out what the compiler should do, given that the operation is allowed. -- Morris M. Keesan {decvax,linus,wjh12,ima}!bbncca!keesan keesan @ BBN-UNIX.ARPA