Re: [PATCH 05/38] refs: create a base class "ref_store" for files_ref_store
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 9, 2016, 16:14 UTC
- Message-ID
- <xmqq60tijq4g.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <575978DA.30608@alum.mit.edu>
Michael Haggerty <mhagger@alum.mit.edu> writes:
Show 14 quoted lines
>>> + >>> +static struct ref_store *main_ref_store = NULL; >>> + >>> +static struct ref_store *submodule_ref_stores = NULL; >> >> Let's let BSS take care of these initialization. > > I like the `= NULL` because it expresses "yes, I care about the initial > values of these variables", which to me is more valuable than saving a > few bytes in the size of the executable. But in fact, GCC does the > obvious optimization: it detects that these variables are being > initialized to zero, and puts them in BSS anyway. I'd be surprised if > other compilers don't do the same. So I'd prefer to leave this as-is, if > it's OK with you.
Sorry; I shouldn't have phrased it with BSS, because the main point of the convention is not about "saving bytes by placing it in BSS".
Lack of "= ..." is a clear-enough clue that the code wants these pointers initialized to NULL. And in this snippet:
static struct foo the_foo;
static struct foo *default_foo = &the_foo;
static struct foo *other_foo;we want the presence of "=" as a clue that something special is going on only for default_foo (it is not initialied to the nul value for the type like usual static variables). If you wrote it this way,
static struct foo *default_foo = &the_foo;
static struct foo *other_foo = NULL;the reader has to say "something funny going on about other_foo?" when scanning up to "other_foo =" and then "... ah, no that is just wasted typing and reading, it is left to NULL after all".
So, no, it is not OK with me.
Otherwise I would have said "I wonder if ..." ;-)