To dereference or not dereference, that is the question

Chris Torek chris at umcp-cs.UUCP
Tue Mar 4 12:10:12 AEST 1986


In article <196 at aplvax.UUCP> ded at aplvax.UUCP (Don E. Davis) writes:

>... It doesn't seem to matter if I deference function pointers or not.
>This seems wrong to me.

... followed by a code sample including the declaration and call:

	int (*y)();
	...
	y(2);

The call is wrong.  It `just happens' to work in PCC-based compilers.
Try compiling the following:

	main()
	{
		int f(), (*p)();

		p = f;
		p(1);
		(*p)(2);
		(**p)(3);
		(****************p)(4);
	}

	f(x)
		int x;
	{

		printf("%d\n", x);
	}

Just because it works in your compiler (and in mine) does not mean
it is correct....

Of course, the only thing you can do with a pointer to a function
is take its address, take its value, or call through it.  PCC seems
to figure that if you are not doing either of the former, you must
be doing the latter, and does not care how many indirections were
actually used.  While this is a bug in PCC, it does not seem a very
important one.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1415)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at mimsy.umd.edu



More information about the Comp.lang.c mailing list