Re: Declaring vars at first use

Chip Salzenberg (chip@perlsupport.com)
Wed, 21 Oct 1998 15:26:56 -0400


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/