Re: Declaring vars at first use

David Mandala (davidm@them.com)
Wed, 21 Oct 1998 15:27:31 -0700


Assuming that all of this takes place in a single function a single and
slight change makes it work.:

#ifdef FOOBAR
{
int foo_var;
foo_var = foo_init();
#endif
...
#ifdef FOOBAR
foo_use(foo_var);
#endif
...
#ifdef FOOBAR
foo_use_again(foo_var);
}
#endif

Though I agree that it means you must track the last use of #ifdef FOOBAR
which is a bit inconvient but it will work cleanly.

Quoting Chip Salzenberg (chip@perlsupport.com):
> According to Matthias Urlichs:
> > In dist.linux.kernel, article <908456202.25458@noris.de>,
> > Chip Salzenberg <chip@perlsupport.com> writes:
> > > Experience indicates otherwise. And consider how inconvenient it is
> > > now to have two ifdef blocks -- one for the conditional code itself
> > > and another at the top of the function for the variables that the code
> > > needs. Bleh.
> >
> > Whatever happened to the idea of
> > #ifdef FOOBAR
> > {
> > int foo_now, bar_later;
> > [...]
> > }
> > #endif
> > ?
>
> That's great unless you have this:
>
> #ifdef FOOBAR
> int foo_var = foo_init();
> #endif
> ...
> #ifdef FOOBAR
> foo_use(foo_var);
> #endif
> ...
> #ifdef FOOBAR
> foo_use_again(foo_var);
> #endif
>
> The C++ approach also makes ifdef'ing existing code easier -- you often
> don't have to introduce new scopes that the C approach would require.
> --
> Chip Salzenberg - a.k.a. - <chip@perlsupport.com>
> "... under cover of afternoon in the biggest car in the county?!" //MST3K
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.rutgers.edu
> Please read the FAQ at http://www.tux.org/lkml/

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/