Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!bloom-beacon!drk From: drk@athena.mit.edu (David R Kohr) Newsgroups: comp.lang.c++ Subject: Re: C++ coding standards (Comment needed) Summary: You can't jump over an "embedded" declaration Keywords: standard,variables Message-ID: <1990Aug19.160307.20972@athena.mit.edu> Date: 19 Aug 90 16:03:07 GMT References: <2161@runxtsa.runx.oz.au> <425@mole-end.UUCP> Sender: daemon@athena.mit.edu (Mr Background) Organization: Massachusetts Institute of Technology Lines: 30 In this discussion of the benefits and drawbacks of declaring variables at their point of use in a block in C++, rather than at the beginning of a block as is required in C, I don't recall anyone making the following point: you can't jump (using "goto") past a declaration with an initializer unless that declaration is within a block nested within the current block. (This is according to Stroustrup, _The_C++_Programming_ Language_, p. 296, section 9.11 of the C++ reference manual chapter; I assume it's still true in AT&T C++ 2.0, but I don't have any reference for that version on hand.) There are those of us who occassionally use "goto" for efficiency reasons (or even to make the code clearer). It seems awkward and error-prone to me to have to consciously avoid jumping over declarations with initializers each time one uses a "goto", and to have to check that each declaration with an initializer is not in a code segment which can possibly be skipped over by a "goto". Such awkwardness does not lend itself to making code more maintainable. This subtle mistake probably does not appear very often in practice, since the "goto" is not used with great frequency in C++, but when it does appear it is probably fairly difficult for the programmer to detect, much like use of an uninitialized variable. However, compilers can easily detect instances of the use of uninitialized variables, while detecting the "goto" error requires a more extensive analysis of the code's flow-of-control. -- David R. Kohr M.I.T. Lincoln Laboratory Group 45 ("Radars 'R' Us") email: DRK@ATHENA.MIT.EDU (preferred) or KOHR@LL.LL.MIT.EDU phone: (617)981-0775 (work) or (617)527-3908 (home)