Path: utzoo!attcan!uunet!husc6!ukma!mailrus!uflorida!haven!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: A cast pointer is NOT an lvalue!? (ANSI C) Keywords: X3J11, pointers, cast, lvalue Message-ID: <14445@mimsy.UUCP> Date: 9 Nov 88 19:22:11 GMT References: <479@midgard.mn.org> <10034@socslgw.csl.sony.JUNET> <42234@yale-celray.yale.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 29 In article <42234@yale-celray.yale.UUCP> wald-david@CS.YALE.EDU (david wald) writes: >How about: > > value = *(long *)argp; > argp = (argtype *)((char *)argp + sizeof(long *)); > >where argtype is the type of *argp? You can write that, and it will probably compile, but it may not do anything useful, and may even crash. As a concession to weird architectures, the dpANS grants license to store pointers to things of varying sizes in cells of varying sizes. In particular, if `argtype' is, say, double, there may not be enough bits in it to retain a pointer to a long, and code like while (argp < endp) { (void) printf("%ld\n", *(long *)argp); argp = (double *)((char *)argp + sizeof(long *)); } may loop forever printing the same value each time. As a concession to getting work done, however, the dpANS grants license to use something similar to varargs to do the job. So why not use it instead of trying to come up with an alternative? -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris