Casting pointers

Christopher R Volpe volpe at underdog.crd.ge.com
Thu Jul 19 23:45:49 AEST 1990


In article <1614 at ghost.stsci.edu>, davids at 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. (Never seen it
in K&R.) But it sometimes does bizarre things. Consider the following
code:                     
main()
{ int i;
  float f;

  f=2.0;
  (float) i = f;
  printf("i==%d\n",i);
}

Compiled with Sun C, this program prints:
i==1073741824

Compiled with gcc, it prints
i==2

Chris Volpe



More information about the Comp.lang.c mailing list