dlee@s.cs.uiuc.edu (11/16/88)
I usually don't have any trouble with C, but this is a glaring exception: I
need the syntax of definition for an array (of arbitrary size) of pointers to
functions returning pointers to integer (HOW'S *THAT* FOR A DOOZY!!!). My
closest (possibly correct) guess follows:
int *(*opfuncs[])() = {
.
.
.
};
I would appreciate any corrections/verifications.
Thanks in advance,
Doug Lee
english@stromboli.usc.edu (Joe English) (11/19/88)
In article <207600008@s.cs.uiuc.edu> dlee@s.cs.uiuc.edu writes: > >I usually don't have any trouble with C, but this is a glaring exception: I >need the syntax of definition for an array (of arbitrary size) of pointers to >functions returning pointers to integer (HOW'S *THAT* FOR A DOOZY!!!). Let's see, that would be int *(*a)()[], umm, int (*)[][](a), no, er, int (**a[*])(:-), no, um, hmph... typedef int *(*pfpi)(); pfpi opfuncs[]; So that would make opfuncs of type: >My closest (possibly correct) guess follows: > > int *(*opfuncs[])() = { ^^^^^^^^^^^^^^^^^^^ about like that. >Doug Lee --Joe English
dlee@s.cs.uiuc.edu (11/19/88)
Thanks for all the replies, guys. Everybody seems to agree both that my declaration was correct and that I should get a copy of cdecl. Doug
rgh@inmet (11/19/88)
>I need the syntax of definition for an array (of arbitrary size) of pointers to >functions returning pointers to integer (HOW'S *THAT* FOR A DOOZY!!!). My >closest (possibly correct) guess follows: > > int *(*opfuncs[])() = { . . . }; > > I would appreciate any corrections/verifications. It looks correct to me. What I would recommend, though, would be something like: typedef int * (*opfunc_t)(); opfunc_t opfuncs[] = { . . . }; Divide and conquer. Randy Hudson rgh@inmet.inmet.com uunet!inmet!rgh
danr@hcx2.SSD.HARRIS.COM (11/20/88)
/* Written 12:09 am Nov 16, 1988 by dlee@s.cs.uiuc.edu in hcx2:comp.lang.c */ /* ---------- "help with a MESSY C definition!!?" ---------- */ > [intro] I > need the syntax of definition for an array (of arbitrary size) of pointers to > functions returning pointers to integer (HOW'S *THAT* FOR A DOOZY!!!). My > closest (possibly correct) guess follows: > > int *(*opfuncs[])() = { > . > . > . > }; > >I would appreciate any corrections/verifications. > Doug Lee /* End of text from hcx2:comp.lang.c */ By my copy of cdecl: me: "explain int *(*opfuncs[])()" cdecl: "declare opfuncs as array of pointer to function returning pointer to int" so it looks as though you hit the right one on the first shot. Good luck. ______________________________________________________________________________ PARA-QUOTE: It is better to remain quiet and be thought a fool, than to open one's mouth and remove all shade of doubt. ______________________________________________________________________________ || Internet: danr@hcx1.ssd.harris.com Daniel G. Rittersdorf || Harris Corporation || ...!novavax---\ Computer Systems Division || UUCP: ...!uunet-------!hcx1!danr Fort Lauderdale, FL 33309 || ...!mit-eddie-/ || ------------------------------------------------------------------------------ DISCLAIMER: The opinions expressed above are mine, Mine MINE! Anyone else that wants one will have to look elsewhere. That includes Harris. ------------------------------------------------------------------------------
nts0699@dsacg1.UUCP (Gene McManus) (11/22/88)
From article <13526@oberon.USC.EDU>, by english@stromboli.usc.edu (Joe English): > In article <207600008@s.cs.uiuc.edu> dlee@s.cs.uiuc.edu writes: >> >>I usually don't have any trouble with C, but this is a glaring exception: I >>need the syntax of definition for an array (of arbitrary size) of pointers to >>functions returning pointers to integer (HOW'S *THAT* FOR A DOOZY!!!). > >>Doug Lee A recent (the last?) Microsoft Journal had what seemed to me to be an excellent article which removed a lot of my fog on the subject of declarations in C. Gene McManus
warren@wwd.UUCP (Warren Burstein) (11/22/88)
In article <13526@oberon.USC.EDU> english@stromboli.usc.edu (Joe English) writes: >Let's see, that would be int *(*a)()[], umm, int (*)[][](a), no, er, >int (**a[*])(:-), no, um, hmph... /\ I don't have my ansi book handy, is this the new "bitwise mung" op, in which the compiler has a laugh at the programmer's expense? -- /|/-\/-\ The entire world |__/__/_/ is a very strange carrot |warren@ But the farmer / wwd.UUCP is not worried at all.
bph@buengc.BU.EDU (Blair P. Houghton) (11/22/88)
In article <207600008@s.cs.uiuc.edu> dlee@s.cs.uiuc.edu writes: > >I usually don't have any trouble with C, but this is a glaring exception: I >need the syntax of definition for an array (of arbitrary size) of pointers to >functions returning pointers to integer (HOW'S *THAT* FOR A DOOZY!!!). My >closest (possibly correct) guess follows: > > int *(*opfuncs[])() = { > . > . > . > }; Let's play precedence: opfuncs[] is an array; *opfuncs[] is an array of pointers (*opfuncs[])() is an array of pointers to function *(*opfuncs[])() is an array of pointers to function returning pointer int *(*opfuncs[])() is an array of pointers to function returning pointer to int. I'll buy it. Now, prove that (int *(*)()) is unambiguously "cast to pointer to function returning pointer to int" and never misinterpreted as "cast to function returning pointer to pointer to int," whatever the hell that means... --Blair "Take two asterisks and call me in the morning."
friedl@vsi.COM (Stephen J. Friedl) (11/25/88)
In article <1506@buengc.BU.EDU>, bph@buengc.BU.EDU (Blair P. Houghton) writes: > Now, prove that > > (int *(*)()) > > is unambiguously "cast to pointer to function returning pointer > to int" and never misinterpreted as "cast to function returning pointer > to pointer to int," whatever the hell that means... Casts are "abstract declarations". This means that if you drop the outer parens, there is exactly one place where a variable name (say, `foo') could be inserted to make this a real declaration. Above, the only place would be: int *(*foo)() So, this is "cast to ptr to function returning ptr to int". Steve -- Steve Friedl V-Systems, Inc. +1 714 545 6442 3B2-kind-of-guy friedl@vsi.com {backbones}!vsi.com!friedl attmail!vsi!friedl ------------Nancy Reagan on climaxes: "Just say moan!"------------- :wq!
bph@buengc.BU.EDU (Blair P. Houghton) (11/26/88)
In article <950@vsi.COM> friedl@vsi.COM (Stephen J. Friedl) writes: >In article <1506@buengc.BU.EDU>, bph@buengc.BU.EDU (Blair P. Houghton) writes: >> Now, prove that >> >> (int *(*)()) >> >> is unambiguously "cast to pointer to function returning pointer >> to int" and never misinterpreted as "cast to function returning pointer >> to pointer to int," whatever the hell that means... > >Casts are "abstract declarations". This means that if you drop the >outer parens, there is exactly one place where a variable name (say, >`foo') could be inserted to make this a real declaration. Above, >the only place would be: > > int *(*foo)() > >So, this is "cast to ptr to function returning ptr to int". 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? */ --Blair
w-colinp@microsoft.UUCP (Colin Plumb) (11/26/88)
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!