Date: Wed, 4 Jul 2001 21:26:24 +0200 From: Jens Schweikhardt <schweikh@schweikhardt.net> To: Joerg Wunsch <joerg_wunsch@uriah.heep.sax.de> Cc: cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/sys/sys bio.h Message-ID: <20010704212624.A1812@schweikhardt.net> In-Reply-To: <20010703233321.C3398@uriah.heep.sax.de>; from j@uriah.heep.sax.de on Tue, Jul 03, 2001 at 11:33:21PM %2B0200 References: <20010703193214.A3398@uriah.heep.sax.de> <200107032051.f63KpIm01502@mass.dis.org> <20010703233321.C3398@uriah.heep.sax.de>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Jul 03, 2001 at 11:33:21PM +0200, Joerg Wunsch wrote: # As Mike Smith wrote: ... # > > Also, using a void * would have complicated matters pretty much. It's # > > invalid to abuse a void * as an int # > # > Er, no it's not. # > # > void *foo; # > int bar; # > # > bar = (int)(uintptr_t)foo; # > # > foo = (void *)(uintptr_t)bar; # # I think that's wrong C. AFAIR, an arbitrary /pointer/ is allowed to # be cast to a void *, and then cast back to just that arbitrary s/cast/assigned to/g void pointers exist to fill^Wopen a gap in the type system. Casting pointers to and from void* is a silly thing to do outside variable arg lists (and only done by the C++ infected where it is rquired :-) # pointer, and this is the only valid operation on void pointers. # Casting a scaler type to a void * and back is not a valid operation. # (First, the machine might have a different bit length for pointers and # scalars, and IMHO it's even possible that a machine has an entirely # different address space for pointers and scalars, something like the # IA32 architecture has different address spaces for memory and IO # pointers.) # # Someone with a better standards background than me might comment on # this. For the time being, here's the reference to K&R2 (p 199): # # ``A6.8 Pointers to Void # # Any pointer to an object may be converted to type void * without loss # of information. If the result is converted back to the original # pointer type, the original pointer is recovered. [...]'' # # So only pointers are allowed here. In ISO C (89 and 99) assignment between pointers and integers without a cast requires a diagnostic (see the constraints in "simple assignment".) However, implementations are free to DTRT upon encountering things like char *p = (char *)0xf00baa; and gcc certainly has done what you would expect ever since. It might even be documented to work, if in the source... Regards, Jens -- Jens Schweikhardt http://www.schweikhardt.net/ SIGSIG -- signature too long (core dumped) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010704212624.A1812>