mleisher@nmsu.edu (Mark Leisher) (04/12/89)
Can anyone tell me what is wrong with this: void junk( int a, int b ) { cout << a << "\n" << b; } void fill( (*f[])(int, int) ) { int i; for ( i = 0; i < 128; i++ ) f[i] = junk; } main() { void (*func_tbl[128])(int, int); fill( func_tbl ); } Mark Leisher New Mexico State University mleisher@nmsu.edu
schmidt@zola.ics.uci.edu (Doug Schmidt) (04/13/89)
In article <MLEISHER.89Apr12105742@tesuque.nmsu.edu> mleisher@nmsu.edu (Mark Leisher) writes: ++ Can anyone tell me what is wrong with this: ++ [original program omitted, revised version presented below] Sure. First of all, you forgot the `void' before the formal declaration of (*f[])(int, int) in function fill. Secondly, cfront 1.2.1 and G++ have problems grokking complex pointer-to-function-etc declarations. Putting the keyword `auto' in strategic places provides enough context to the parser so that the program is properly recognized. The following revised version compiles correctly with both cfront 1.2.1 and G++. I don't know if cfront 2.0 fixes this problem. Doug ---------------------------------------- #include <stream.h> void junk( int a, int b ) { cout << a << "\n" << b; } void fill( auto void (*f[])(int, int) ) { int i; for ( i = 0; i < 128; i++ ) f[i] = junk; } main() { auto void (*func_tbl[128])(int, int); fill( func_tbl ); } ---------------------------------------- -- On a clear day, under blue skies, there is no need to seek. And asking about Buddha +------------------------+ Is like proclaiming innocence, | schmidt@ics.uci.edu | With loot in your pocket. | office: (714) 856-4043 |
diamond@diamond.csl.sony.junet (Norman Diamond) (04/13/89)
In article <MLEISHER.89Apr12105742@tesuque.nmsu.edu> mleisher@nmsu.edu (Mark Leisher)
asks for help with:
1 > void junk( int a, int b )
2 > {
3 > cout << a << "\n" << b;
4 > }
5 > void fill( (*f[])(int, int) )
6 > {
7 > int i;
8 > for ( i = 0; i < 128; i++ )
9 > f[i] = junk;
10 > }
11 > main()
12 > {
13 > void (*func_tbl[128])(int, int);
14 > fill( func_tbl );
15 > }
In line 9, *f[i] must return an int but junk returns void.
In line 14, a similar type mismatch occurs.
Try for line 5:
void fill( void (*f[])(int, int) )
Unfortunately g++ still dislikes it. Whose c++ are you using?
Norman Diamond, Sony Computer Science Lab (diamond%csl.sony.jp@relay.cs.net)
The above opinions are my own. | Why are programmers criticized for
If they're also your opinions, | re-inventing the wheel, when car
you're infringing my copyright. | manufacturers are praised for it?
ark@alice.UUCP (Andrew Koenig) (04/13/89)
In article <11888@paris.ics.uci.edu>, schmidt@zola.ics.uci.edu (Doug Schmidt) writes: > In article <MLEISHER.89Apr12105742@tesuque.nmsu.edu> mleisher@nmsu.edu (Mark Leisher) writes: > I don't know if cfront 2.0 fixes this problem. It will be much better about it. For example, it will accept this: void fill( void (*f[])(int, int) ) { /* ... */ } -- --Andrew Koenig ark@europa.att.com