From: René Scharfe Date: Thu, 09 May 2013 14:32:55 GMT Subject: Re: [PATCH 3/3] Initialize variables with values Message-ID: <518BB397.901@lsrfire.ath.cx> In-Reply-To: <20130509132115.GA3375@elie> Am 09.05.2013 15:21, schrieb Jonathan Nieder: > Hi, > > Sven Strickroth wrote: > >> With MSVC initializing a variable with "int a=a" causes a warning about >> using an uninitialized value. > [...] >> --- a/builtin/rev-list.c >> +++ b/builtin/rev-list.c >> @@ -338,7 +338,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix) >> mark_edges_uninteresting(revs.commits, &revs, show_edge); >> >> if (bisect_list) { >> - int reaches = reaches, all = all; >> + int reaches = 0, all = 0; > > A correct way to spell this is > > int reaches, all; > > which, as a bonus, lets the compiler warn if they are used > uninitialized. Does that provoke warnings? Only find_bisection() (defined in bisect.c) is used to set these variables in that block. While it sets "all" unconditionally, it doesn't always set "reaches" -- only if it actually finds something. That's still safe because the following code path errors out early if nothing was found before it uses "reaches". Are there C compilers that can analyse initialization and usage of variables across compilation units like that? Anyway, initializing the variables to zero makes this code consistent with the second call-site of find_bisection(). Making sure this function sets "reaches" unconditionally as well and dropping the initialization from both places may be even better. René