herndon@umn-cs.UUCP (03/02/85)
Does anyone know of a solution for the following problems? 1) The C compiler (4.2bsd) barfs on the following: void foo() {...} void blort() {...} void (*f[]) () = { foo, /* Operands of = have incompat. types*/ blort, /* Ditto. */ 0 } though it accepts: int foo() {...} int blort() {...} int (*f[])() = { foo, blort, 0 }; This doesn't seem rational to me. If I declare foo and blort in the first example to be integer, then it only gives me warnings. 2) When I try to pass a union as an argument to a function (again, 4.2bsd), the C compiler usually works. Unfortunately, it often doesn't work. It frequently dies with no error message at all, or else a mysterious message to the effect of "Op STASHG missing from op-code table". The unions in question all fit into one word. Are these really bugs, or am I missing something?
ndiamond@watdaisy.UUCP (Norman Diamond) (03/04/85)
> 1) The C compiler (4.2bsd) barfs on the following: > void foo() {...} > void blort() {...} > void (*f[]) () = { > foo, /* Operands of = have incompat. types*/ > blort, /* Ditto. */ > 0 > } It's true. f /* array of pointers */ cannot be initialized to functions. In the other cases originally cited, integers could be initialized to pointers, but the conversion is implementation-dependent. If you want to initialize pointers to pointers, try: void foo() {...} void blort() {...} void (*f[]) () = { &foo, &blort, 0 } -- Norman Diamond UUCP: {decvax|utzoo|ihnp4|allegra}!watmath!watdaisy!ndiamond CSNET: ndiamond%watdaisy@waterloo.csnet ARPA: ndiamond%watdaisy%waterloo.csnet@csnet-relay.arpa "Opinions are those of the keyboard, and do not reflect on me or higher-ups."
gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>) (03/06/85)
> void (*f[]) () = { > 2) When I try to pass a union as an argument to a function > Are these really bugs, or am I missing something? They're really bugs.
ron@brl-tgr.ARPA (Ron Natalie <ron>) (03/06/85)
> > 1) The C compiler (4.2bsd) barfs on the following: > > void foo() {...} > > void blort() {...} > > void (*f[]) () = { > > foo, /* Operands of = have incompat. types*/ > > blort, /* Ditto. */ > > 0 > > } > > It's true. f /* array of pointers */ cannot be initialized to functions. > In the other cases originally cited, integers could be initialized to > pointers, but the conversion is implementation-dependent. > > If you want to initialize pointers to pointers, try: > > void foo() {...} > void blort() {...} > void (*f[]) () = { > &foo, > &blort, > 0 > } > WRONG, foo and blort are correctly the address of the function. His example should work, and does if you are using the system V compiler. The 4.2 BSD compiler has a bug that causes makes it imposible to properly declare pointer to functions returning void. Your example cause the warning " & before arraay or function ignored."
ndiamond@watdaisy.UUCP (Norman Diamond) (03/08/85)
> > f /* array of pointers */ cannot be initialized to functions. > > If you want to initialize pointers to pointers, try: > > void foo() {...} > > void blort() {...} > > void (*f[]) () = { > > &foo, > > &blort, > > 0 > > } > > WRONG, foo and blort are correctly the address of the function. > Your example cause the warning " & before array or function ignored." Yup, my mistake. I should have learned by now, not to believe manuals' rules on syntax and such things without trying them out first.... -- Norman Diamond UUCP: {decvax|utzoo|ihnp4|allegra}!watmath!watdaisy!ndiamond CSNET: ndiamond%watdaisy@waterloo.csnet ARPA: ndiamond%watdaisy%waterloo.csnet@csnet-relay.arpa "Opinions are those of the keyboard, and do not reflect on me or higher-ups."