help with a MESSY C definition!!?

Colin Plumb w-colinp at microsoft.UUCP
Sat Nov 26 11:35:32 AEST 1988


In article <1530 at buengc.BU.EDU> bph at buengc.bu.edu (Blair P. Houghton) writes:
>But is there anything illegal about
>
>	int *(*)foo()
>
>and would those "extra" parentheses change the precedence of that *
>declarator at all, viz
>
>	double *barz[]  /* declare barz as array of ptr to double */
>	
>	double (*)barz[]  /* declare barz as ptr to array of double.
>			     Or does it? */

Yes, it is illegal.  To see why, realise that C declaration syntax is
based on the equivalent expression syntax.  That is, in your second
example, *barz[i] is of type double; i.e. I could write sum += *barz[i].
You could also write sum += *(barz[i]), so you could declare barz as
double *(barz[]), or even get ridiculous and, recognising that (*((barz)[i]))
is a valid expression, declare barz as double (*((barz)[])).

However, (*)barz[] is *not* a valid expression, since "*" is not a valid
expression, so your example declaration syntax is invalid.

(Well, on older C compilers which allow:
i, *ip
to declare i as int and ip as pointer to int, (*) is a cast to type
"pointer to int", so (*)barz[i] is a valid expression, but it includes
a type cast, which is not allowed in declaration syntax.
-- 
	-Colin (microsof!w-colinp at sun.com)

P.S. I'm pretty sure that

	typedef int foo;
	{
		foo foo;
		...
	}

declares foo within the inner block to be an int, but can someone quote
chapter and verse from the ANSI C draft that says so?  For some types
(structs and arrays with intialisers), the draft is quite specific on where
a variable becomes visible, and where its type becomes complete, but
I can't find it for "simple" declarations.

Thanks!



More information about the Comp.lang.c mailing list