Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!uc!shamash!bls From: bls@svl.cdc.com (brian scearce) Newsgroups: comp.lang.c Subject: Re: Casting pointers Keywords: cast Message-ID: <23590@shamash.cdc.com> Date: 19 Jul 90 19:09:24 GMT References: <1614@ghost.stsci.edu> <9959@crdgw1.crd.ge.com> Sender: news@shamash.cdc.com Lines: 35 volpe@underdog.crd.ge.com (Christopher R Volpe) writes: >In article <1614@ghost.stsci.edu>, davids@stsci.EDU (David Silberberg) writes: >|>If the last line above were replaced by >|> >|> ptr = (char *)ptr + num_chars; >|> >|>it would perform as desired. Does casting work on an lvalue? >I'm not sure if casting on an l-value is specified anywhere. Harbison & Steele (section 7.5.1): "Any permissible conversion may be invoked by a cast expression. The result is not an lvalue." >main() >{ int i; > float f; > f=2.0; > (float) i = f; ^^^^^^^^^^^^^ This is not legal C. > printf("i==%d\n",i); >} >Compiled with Sun C, this program prints: i==1073741824 >Compiled with gcc, it prints: i==2 It shouldn't compile at all. The mighty CDC C Version 2 prints, "Operation can only be performed on lvalues", an excellent diagnostic if I do say so myself :-) -- Brian Scearce \ "I tell you Wellington is a bad general, the English are (not on CDCs behalf) \ bad soldiers; we will settle the matter by lunch time." bls@u02.svl.cdc.com \ -- Napolean Bonaparte, June 18, 1815 (at Waterloo) shamash.cdc.com!u02!bls \ From _The Experts Speak_, Cerf & Navasky