Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!batcomputer!itsgw!steinmetz!davidsen From: davidsen@steinmetz.ge.com (William E. Davidsen Jr) Newsgroups: comp.lang.c Subject: Re: arithmetic on void pointers Message-ID: <13323@steinmetz.ge.com> Date: 7 Mar 89 16:58:48 GMT References: <1527@ncar.ucar.edu> Reply-To: davidsen@crdos1.UUCP (bill davidsen) Organization: General Electric CRD, Schenectady, NY Lines: 29 In article <1527@ncar.ucar.edu> russ@groucho.UUCP (Russ Rew) writes: | GNU C supports arithmetic on void pointers, but the manual implies | that this is an extension to the C language. I could find no | prohibition on arithmetic on void pointers in K&R second edition. | What does the latest dpANS document say? Is it legal to increment a | variable of type void* ? Let's see... a pointer increment on a char pointer adds sizeof(char) to the pointer, increment on int pointer adds sizeof(int), I guess you would conclude that increment on a void pointer would add sizeof(void). I *think* dpANS says sizeof(void) is zero (I don't have it here, so correct me if you can find the section). I conclude that if it was allowed it wouldn't do anything. I don't think it's allowed. One of my C students handed in this code fragment: void *foo, *getsym(); int m; foo = getsym(22); m = (int) foo[4]; I *think* he meant "m = ((int *) foo)[4]" which seems legal if not the clearest way to do it. -- bill davidsen (wedu@ge-crd.arpa) {uunet | philabs}!steinmetz!crdos1!davidsen "Stupidity, like virtue, is its own reward" -me