Casting Question

Spencer W. Thomas thomas at utah-gr.UUCP
Sat Jan 18 09:09:50 AEST 1986


In article <162 at butler.UUCP> chinn at butler.UUCP (David Chinn) writes:
>Inst    *pc;            /* program counter during execution */
>			/* pc is declared to be a pointer to an Inst;
>	.	           or, a pointer to a pointer to a function  */

>        	pc = *((Inst **)(savepc+2));     /* next stmt */
>                     ^^^^^^^^^^^^^^^^^^^^^^
>                      So what is this for?
What appears to be happening here is that the location savepc+2 is a
POINTER to a location containing the desired pc value.  Certainly
(in this case) removing the cast will not affect the code (you are still
dereferencing savepc+2, and the value there is still a pointer), but the
types on the left and right of the assignment DO NOT MATCH!  If you run
lint over the code, it will complain.  The right hand side of the
assignment will be an Inst, while the left side is an Inst *.  The cast
keeps the types right.


-- 
=Spencer   ({ihnp4,decvax}!utah-cs!thomas, thomas at utah-cs.ARPA)
	"Ask not what your kernel can do for you, but rather what you
	 can do for you kernel!"



More information about the Comp.lang.c mailing list