Solution to "A C Puzzle" of 12/12/83

Sam Kendall kendall at wjh12.UUCP
Sat Mar 17 07:42:05 AEST 1984


I posted the following puzzle on 12/12/83:

	For what, if any, subexpressions `p' do the expressions
		*(p)
	and
		(p)[0]
	not have identical meaning?

I received a grand total of two responses, by mail.  One, from
Kenneth Almquist, was correct; the other concluded that there is no
such `p'.

I said that this wasn't a trick question, and I shouldn't have.  The
answer is that for any `p' of type function or pointer to function,
`(p)[0]' doesn't have a meaning.  It expands to `*((p) + 0)', but
pointer addition is illegal for function pointers, because pointer
addition needs to know the size of the pointed-to object, and functions
have no size.

	Sam Kendall		  {allegra,ihnp4}!wjh12!kendall
	Delft Consulting Corp.	    decvax!genrad!wjh12!kendall



More information about the Comp.lang.c mailing list