From: Tanay Abhra Date: Mon, 23 Jun 2014 13:19:52 GMT Subject: Re: [PATCH v3 1/3] string-list: add string_list initialiser helper functions Message-ID: <53A82978.2010900@gmail.com> In-Reply-To: <53A81F45.70802@web.de> On 06/23/2014 05:36 AM, Torsten Bögershausen wrote: > If we look at the definition below: > struct string_list { > struct string_list_item *items; > unsigned int nr, alloc; > unsigned int strdup_strings:1; > compare_strings_fn cmp; /* NULL uses strcmp() */ > I think a simple memset() will be easier to read, > and it will be more future proof: > In case elements are added, the will have 0 or NULL automatically: Yes, you are right. After sending the patch I saw that for string_list initialization the codebase either uses xcalloc or memset and after that marks the list as DUP or NODUP. > void string_list_init_nodup(struct string_list *list) > { > memset (list, 0, sizeof(*list)); > } > (But then I wonder if we need the function at all ?) > > Or does it make sense to have a common function similar to this, > which covers both cases: > > void string_list_init(struct string_list *list, int strdup_strings) > { > memset (list, 0, sizeof(*list)); > list->strdup_strings = strdup_strings; > } > A common function would be much better as other API constructs as strbuf have runtime init functions like the version you have shown above. Thanks for the review.