Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!gamma!epsilon!zeta!sabre!petrus!bellcore!decvax!genrad!panda!talcott!harvard!seismo!umcp-cs!aplcen!aplvax!ded From: ded@aplvax.UUCP (Don E. Davis) Newsgroups: net.lang.c Subject: To dereference or not dereference, that is the question Message-ID: <196@aplvax.UUCP> Date: Mon, 3-Mar-86 10:37:45 EST Article-I.D.: aplvax.196 Posted: Mon Mar 3 10:37:45 1986 Date-Received: Wed, 5-Mar-86 06:37:46 EST Reply-To: ded@aplvax.UUCP (Don E. Davis) Organization: JHU/Applied Physics Lab, Laurel, MD Lines: 51 Keywords: type casts,function pointers In article <857@pucc-j> aaz@pucc-j.UUCP (Marc Mengel) writes: > >char foo[BIGNUM]; >main() >{ > int result; > > /* code to put machine code into foo[] */ > > result = (* (int (*)()) foo)(); >} >-- An interesting corollary to this issue is the following. It doesn't seem to matter if I deference function pointers or not. This seems wrong to me. I feel the y(2) and ((int (*)())x)(3) function invocations should be illegal. #include main(argc, argv) int argc; char **argv; { int x; int (*y)(); /* y is pointer to function returning int */ int func(); y = func; /* y points to func */ (*y)(1); /* dereference y and invoke func */ y(2); /* DON'T dereference y and invoke func! */ /* the same as above with casting */ x = (int)func; ((int (*)())x)(3); (*(int (*)())x)(4); exit(0); } func(param) int param; { printf("hello %d\n", param); } All of the above appear to be equivalent. What the heck is going on here? -- Don Davis JHU/APL ...decvax!harpo!seismo!umcp-cs!aplcen!aplvax!ded ...rlgvax!cvl!umcp-cs!aplcen!aplvax!ded