gjditchfield@violet.waterloo.edu (Glen Ditchfield) (03/31/88)
Here's three possible bugs in C++, using cfront 1.2.1 and BSD4.3 on a Vax. (The CC command has been renamed ccc locally.) 1) Cfront silently absorbs typedefs inside classes, to the confusion of C. ---------------------------------------- class bar { public: typedef int* ip; ip i; }; ---------------------------------------- ccc typedef.cc: cc -c typedef..c "typedef.cc", line 4: syntax error "typedef.cc", line 4: warning: Missing ',' or '=' in variable declaration "typedef.cc", line 4: warning: undeclared initializer name _bar_i "typedef.cc", line 4: illegal initialization "typedef.cc", line 5: syntax error ---------------------------------------- I have no idea how typedef should interact with public/private/protected, but cc should not produce error messages. 2) Declaration of "complex" variables in the middle of code causes confusion about the scope of other variables. ---------------------------------------- #include <stream.h> void foo() { for (int i = 1; i <= 10; i += 1) { } filebuf fb; for (char *i = (char *)0; i != 0; i += 1) { } } ---------------------------------------- If "filebuf fb;" is commented out, the messages produced are ccc redef2.cc: "redef2.cc", line 6: error: two declarations of i Similar messages are produced if the filebuf declaration is replaced by a declaration of an integer and the #include is removed. If "filebuf fb;" is not commented out, the messages produced are ccc redef2.cc: cc -c redef2..c "redef2.cc", line 6: warning: "_au1_i" redefinition hides earlier one Again, a C error is produced. 3) This is more likely to be my misunderstanding than a bug. The syntax in the back of "The C++ Programming Language" suggests that functions can have pointer-to-function parameters, but I get (uninformative) error messages unless I use a typedef. ---------------------------------------- typedef int (*PFCCI)(char, char); // ptr to fn mapping 2 chars to int. void f( PFCCI p); void g( int (*p)(char, char) ); ---------------------------------------- ccc pmf.cc: "pmf.c", line 5: error: syntax error "pmf.cc", line 5: error: syntax error "pmf.cc", line 5: error: syntax error ---------------------------------------- Does C++ require the typedef, or have I just messed up the declaration of g? 4) Is there a better place to send complaints to than this group? The local C++ maintainer doesn't know of one. Glen Ditchfield watmath!violet!gjditchfield Dept of Computer Science, U of Waterloo (519) 885-1211 x6658 Waterloo, Ontario, Canada Office: MC 2006 I'm the compiler user your professors warned you about.
gwr@cord.UUCP (GW Ryan) (04/01/88)
In article <6112@watdragon.waterloo.edu> gjditchfield@violet.UUCP writes: both your cases 1 and 2 work fine in 1.2.3 cfront >3) This is more likely to be my misunderstanding than a bug. The syntax in > the back of "The C++ Programming Language" suggests that functions can > have pointer-to-function parameters, but I get (uninformative) error > messages unless I use a typedef. > ---------------------------------------- > typedef int (*PFCCI)(char, char); // ptr to fn mapping 2 chars to int. > > void f( PFCCI p); > > void g( int (*p)(char, char) ); > ---------------------------------------- > ccc pmf.cc: > "pmf.c", line 5: error: syntax error > "pmf.cc", line 5: error: syntax error > "pmf.cc", line 5: error: syntax error > ---------------------------------------- i don't understand what you are trying to do here. g() is supposed to be a function taking what parameters??? are you trying to say g takes one arg, which is the result of a call to what a PFCCI points at? If so, declare it void g(int); are you trying to pass a function pointer AND the 2 chars to run it on? void g(PFCCI, char, char); i don't think you can explicitly look for calls to g() where the arg is a call to a PFCCI function jerry ryan
gjditchfield@violet.waterloo.edu (Glen Ditchfield) (04/02/88)
In article <552@cord.UUCP> gwr@cord.UUCP (59451-GW Ryan) writes: >In article <6112@watdragon.waterloo.edu> gjditchfield@violet.UUCP writes: >> typedef int (*PFCCI)(char, char); // ptr to fn mapping 2 chars to int. >> void g( int (*p)(char, char) ); >i don't understand what you are trying to do here. g() is supposed to be >a function taking what parameters? I want g() to have one parameter, and I want that parameter to be a pointer to a function that takes two characters and returns an integer. The body of g() will call that parameter with characters of its own choosing. Imagine passing an ordering routine down to a sort function. Here's a more interesting version of the problem, again using Cfront 1.2.1. ---------------------------------------- int f( char* s, int (*p)(char, char) ) { return 0; }; int g( int (*p)(char, char) ) { return 0; }; ---------------------------------------- ccc pmf2.cc: "pmf2.cc", line 3: warning: s not used "pmf2.cc", line 3: warning: p not used "pmf2.cc", line 5: error: syntax error "pmf2.cc", line 5: error: syntax error "pmf2.cc", line 5: error: syntax error "pmf2.cc", line 5: error: syntax error "pmf2.cc", line 6: error: syntax error "pmf2.cc", line 6: error: syntax error "pmf2.cc", line 7: error: syntax error 7 errors ---------------------------------------- One declaration of p is accepted, but the other is illegal. Is g() accepted by later versions of cfront?
gwr@cord.UUCP (GW Ryan) (04/04/88)
In article <6170@watdragon.waterloo.edu> gjditchfield@violet.waterloo.edu (Glen Ditchfield) writes: >In article <552@cord.UUCP> gwr@cord.UUCP (59451-GW Ryan) writes: >>In article <6112@watdragon.waterloo.edu> gjditchfield@violet.UUCP writes: >>> typedef int (*PFCCI)(char, char); // ptr to fn mapping 2 chars to int. >>> void g( int (*p)(char, char) ); >>i don't understand what you are trying to do here. g() is supposed to be >>a function taking what parameters? > <example deleted> OK. *now* I understand what you want. It does seem to be a bug. The following works with cfront 1.2.3 (except for warnings about unused variables x and y): int foo(int x, int (*y)(char, char)) { return 0; } HOWEVER, the following does not work: I get syntax errors: int foo(int (*y)(char, char)) { return 0; } very strange... jerry ryan