muttiah@stable.ecn.purdue.edu (Ranjan S Muttiah) (04/19/91)
/* Is there some way I can control the scope of a variable within a file ? Something similar to #undef when using #define */ int a,b; fn1(..) { .... } fn2(..) { .... } /* beep beep, useful life of a is over */ fn3() { a = 5; <- undefined variable: a ... }
cs450a03@uc780.umd.edu (04/20/91)
Ranjan Muttiah writes: >/* Is there some way I can control the scope of a variable within >a file ? Something similar to #undef when using #define */ > >int a,b; fn1(..){.....} fn2(..){.....} >/* beep beep, useful life of a is over */ >fn3(){ >a = 5; <- undefined variable: a >.... Not really, but you could always do something like #define a !@%$#@ Raul Rockwell
imc@prg.ox.ac.uk (Ian Collier) (04/20/91)
In article <1991Apr19.151959.6847@noose.ecn.purdue.edu>, muttiah@stable.ecn.purdue.edu (Ranjan S Muttiah) wrote: >/* Is there some way I can control the scope of a variable within >a file ? Something similar to #undef when using #define */ >int a,b; ... >/* beep beep, useful life of a is over */ ... >a = 5; <- undefined variable: a How about: #define a Undefined_a ? The compiler will complain when you try to use the variable Undefined_a in fn3(). Of course you'll have to #undef it again if you want to use a later on, or if you want a local variable named a (probably bad programming practice). Or perhaps it's better to call your local variable Undefined_a? :-) Not the best idea in the world, but it probably works :-) Ian Collier Ian.Collier@prg.ox.ac.uk | imc@ecs.ox.ac.uk
dan@kfw.COM (Dan Mick) (04/23/91)
In article <1991Apr19.151959.6847@noose.ecn.purdue.edu> muttiah@stable.ecn.purdue.edu (Ranjan S Muttiah) writes: >/* Is there some way I can control the scope of a variable within >a file ? Something similar to #undef when using #define */ > >int a,b; > >fn1(..) >{ >.... >} > >fn2(..) >{ >.... >} > >/* beep beep, useful life of a is over */ > >fn3() >{ > >a = 5; <- undefined variable: a >... >} Yes. Split the file in two. Why on earth would you want to do something to completely frustrate the next person that looks at your code? There's no reason to "unscope" a variable; if that's what you want, use the perfectly good mechanism of splitting the file and making the variable have file scope (i.e., not extern). I mean, there may *be* a way to do this, but you really shouldn't want to. Honest.