lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fix uninitialized variables when Source_file::get_counts returns ear


From: Reinhold Kainhofer
Subject: Re: Fix uninitialized variables when Source_file::get_counts returns early due to !contains (pos_str0) (issue 4940047)
Date: Wed, 24 Aug 2011 11:10:32 +0200
User-agent: KMail/1.13.6 (Linux/2.6.38-10-generic; KDE/4.7.0; i686; ; )

Am Wednesday, 24. August 2011, 10:49:30 schrieben Sie:
> Hi  Graham, Carl,
> 
> On Tue 23 Aug 2011 19:34:37 BST, Carl Sorensen wrote:
> > On 8/23/11 12:21 PM, "address@hidden" <address@hidden> wrote:
> >> Maybe we should have some GOP rules for C++ about this?
> >> "Only have multiple exit points from routines if you absolutely have to.

There is really not much difference in

if (some_condition)
  return;

and

if (!some_condition)
  {
    ....
  }

Except that if you have many conditions the indentation in the second example 
will be terrible and make the whole thing hard to read.

You can mess up equally with both.

> Declaring variables nearest to where they are used + insisting they are
> initialised may work, providing we spell it out the if they are
> declared as parameters to the routine, that's the first place they're
> used, so if they're output parameters, they need to be initialized
> either at the top of the routine, or in the parameter declaration.

Please note that in this case we are talking about a function that is expected 
to modify its arguments, this is NOT about variable declarations. These 
variables, passed-by-reference, should be initialized as soon as possible.

For variable declarations, of course I'm all for moving the declaration 
immediately before the first use.

Cheers,
Reinhold

-- 
------------------------------------------------------------------
Reinhold Kainhofer, address@hidden, http://reinhold.kainhofer.com/
 * Financial & Actuarial Math., Vienna Univ. of Technology, Austria
 * http://www.fam.tuwien.ac.at/, DVR: 0005886
 * LilyPond, Music typesetting, http://www.lilypond.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]