rfg@pink.ACA.MCC.COM (Ron Guilmette) (07/04/89)
I thought that the scope rules of C++ were supposed to be mostly identical to those of ANSI-C. I have just noticed a possible (minor) exception. It seems that types can be declared within formal parameter lists (in both C++ and ANSI C) and that these types have file-scope in C++ but they have function-prototype scope in ANSI C. I'm a fan of strict-typing and (in my view) I'd like to see the first six functions be illegal in C++ (i.e. enforcement of the ANSI-C scoping rules). I just compiled this file with GNU G++ (1.35.0) and *none* of the six were flagged with errors. Does Cfront 2.0 do the same as G++? At the very least it seems that the last two (of the first six) functions should be flagged as having errors because there is simply no way to call them (from the outside). If the scope rules for C++ were the same as those for ANSI-C, there would be no way to call *any* of these six functions, and thus, they could *all* be treated as "illegal". -------------------------------------------------------------------------------- void function_1a (enum E_1a { Evalue_1a } p) { // OK - E_1a has file scope // this differs from ANSI C p = p; } void function_1b (struct S_1b { int Sfield_1b; } p) { // OK - S_1b has file scope // this differs from ANSI C p = p; } void function_1c (union U_1c { int Ufield_1c; } p) { // OK - U_1c has file scope // this differs from ANSI C p = p; } void function_2a (enum { Evalue_2a } p) { // OK ?? - can be called! ? // - whatza scope of Evalue_2a ?? p = p; } void function_2b (struct { int Sfield_2b; } p) { // ERROR - calls are impossible p = p; } void function_2c (union { int Ufield_2c; } p) { // ERROR - calls are impossible p = p; } void test () { enum E_1a e_1a; // OK struct S_1b s_1b; // OK union U_1c u_1c; // OK function_1a (e_1a); // OK function_1b (s_1b); // OK function_1c (u_1c); // OK function_2a (Evalue_2a); // OK ?? - whatza scope of Evalue_2a? } -------------------------------------------------------------------------------- -- // Ron Guilmette - MCC - Experimental Systems Kit Project // 3500 West Balcones Center Drive, Austin, TX 78759 - (512)338-3740 // ARPA: rfg@mcc.com // UUCP: {rutgers,uunet,gatech,ames,pyramid}!cs.utexas.edu!pp!rfg