Casting Question

David Chinn chinn at butler.UUCP
Tue Jan 14 15:24:57 AEST 1986


*** REPLACE THIS LINE WITH YOUR MESSAGE ***
I have been looking at hoc, which appeared on the net
some time ago.  I am relatively new to the language (C)
and so was puzzled by the following ....


typedef int (*Inst)();  /* machine instruction */
			/* Inst is typedefed to a "pointer to a function
			   returning an integer */
	.

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  */
		
ifcode()
{
	Inst *savepc= pc;     /* then part */
			      /* savepc is the same as pc */

        	pc = *((Inst **)(savepc+2));     /* next stmt */
                     ^^^^^^^^^^^^^^^^^^^^^^
                      So what is this for?

}

I understand that the cast makes it (savepc+2) a pointer to a pointer to
an Inst (or a pointer to a pointer to a pointer to a function returning
an integer).  But then the de-referencing star on the outside takes one
level of indirection away, making savepc+2 what it was anyway ( a
pointer to a pointer to a function returning an integer.)

I compiled hoc and tested the if statement; it worked.  I edited code.c
and removed the seemingly extraneous cast and de-ref: it still worked.

Any enlightenment would be appreciated....

    ... uw-beaver                                david m chinn
           !{tikal,teltone}                      box 2249
	       !dataio!butler!chinn     	 kirkland, wash 98083



More information about the Comp.lang.c mailing list