Topic: goto bypasses initialization of local variable: so what? let me


Author: Dennis Yelle <dennis51@jps.net>
Date: Wed, 25 Apr 2001 00:24:21 GMT
Raw View
Tony wrote:
>
> With the rule in the subject line enforced, some of the benefit of being
> able to declare variables
> anywhere within a function, not just at the top, is lost. I don' t mean this
> to turn into a discussion
> about whether or not 'goto' should be used at all though. I find the error
> msg annoying. What are
> your opinions?

There are a couple of ways to deal with this:

1.  Replace this:

        int i = 0;

    with this:

        int i;
        i = 0;

2. Put some more of these { } in the code.
   That is, replace this:

      goto there;
      // ...
      int i = 0;
      // ...
      there:

   With this:

      goto there;
      // ...
      {
         int i = 0;
         // ...
      }
      // ...
      there:


In general, classes with constructors MUST be initialized,
so the general rule is good.  With the work arounds above,
it is not hard to obey the rule for simple variables.

Dennis Yelle
--
I am a computer programmer and I am looking for a job.
There is a link to my resume here:
http://table.jps.net/~vert/

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]