Topic: A possibly stupid proposal


Author: purtill@morley.rutgers.edu (Mark Purtill)
Date: 7 Mar 91 17:38:15 GMT
Raw View
I often get compile error when I do things like this:

 for( int i=0; ...; ...) {
  ...
 }
 ...
 for( int i=0; ...; ...) { // ``i redeclared'' error here
  ...
 }

 While this is admittedly fairly dim of me, I'd rather fix C++
than learn to avoid the error, so I propose that redeclarations be
allowed.
 The old object would be destroyed (if necessary) and the new
one created.  To allow the destruction of an object without creating a
new one, I propose allowing the declaration 'void foo'.  Any attempt
to access foo would be an error.  'static' and 'extern' objects would
still give errors if you tried to redeclare them.
 This doesn't break any code, since currently any code that
this would apply to would have the redeclaration error now.  In
particular, code like:

 int foo ;
 ...
 {    int foo ;   // the outside foo is NOT destroyed here.
      ....
 }

would still work the same way as it does now -- the interior 'foo'
would shadow, not destroy, the exterior 'foo'.
 In addition to allowing each 'for' to declare its own 'int i'
(which would presumably be appreciated by those who think that the
scope of those variables should end at the end of the 'for' loop),
this would also allow more control over when auto objects were created
and destroyed;  I seem to remember postings a while back that wanted
this.  (So don't judge the proposal simply on the basis of my silly
rationale.)
 On the down side, it would allow some authentic errors to get
through, causing confusion.  But probably not much more confusion than
shadowing already does.
 Opinions (even if only "that's the stupidest thing I've ever
seen") welcome.  Flames (as in "you're an idiot for having proposed
this") to /dev/null.

^.-.^ Mark Purtill         purtill@dimacs.rutgers.edu         (908)932-4580 (O)
((")) DIMACS, P.O. Box 1179, Rutgers U., Piscataway, NJ 08855 (908)220-6905 (H)
********** Note new area code!  We are now (908) rather than (201)!  **********