Re: [PATCH v5 2/3] advice: revamp advise API
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Feb 26, 2020, 03:03 UTC
- Message-ID
- <xmqq8skqkq35.fsf@gitster-ct.c.googlers.com>
- In-Reply-To
- <CACg5j25EdX2fPHpAq3TEhaJPiQg4dA52soOyCMm17wg_O-c4Ng@mail.gmail.com>
Heba Waly <heba.waly@gmail.com> writes:
> I'm not against this approach as well, but as I mentioned above, we > need a list of keys to be returned by list_config_advices(), that's > why defining the constant strings will not be sufficient in our case.
Sorry, but I do not get it.
Either you use enum or a bunch of variables of type const char [], "list all of them" would need an array whose elements are all of them, so
const char ADVICE_FOO[] = "advice.foo";
const char ADVICE_BAR[] = "advice.bar";
... static const char *all_advice_type[] = {
ADVICE_FOO, ADVICE_BAR, ...
}; void for_each_advice_type(int (*fn)(const char *name))
{
int i;
for (i = 0; i < ARRAY_SIZE(all_advice_type); i++)
fn(all_advice_type[i]);
}would be sufficient, and I do not think it takes any more effort to create and manage than using an array indexed with the enum, no?