Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!cornell!uw-beaver!microsoft!w-colinp From: w-colinp@microsoft.UUCP (Colin Plumb) Newsgroups: comp.lang.c Subject: Re: help with a MESSY C definition!!? Message-ID: <1007@microsoft.UUCP> Date: 26 Nov 88 01:35:32 GMT References: <207600008@s.cs.uiuc.edu> <1506@buengc.BU.EDU> <950@vsi.COM> <1530@buengc.BU.EDU> Reply-To: w-colinp@microsoft.UUCP (Colin Plumb) Organization: Microsoft Corp., Redmond WA Lines: 46 Confusion: Microsoft Corp., Redmond WA In article <1530@buengc.BU.EDU> bph@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@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!