From: Eric Sunshine Date: Thu, 13 Mar 2014 22:45:06 GMT Subject: Re: [PATCH v4] install_branch_config: simplify verbose messages logic Message-ID: In-Reply-To: On Thu, Mar 13, 2014 at 4:35 PM, Eric Sunshine wrote: > A more table-driven approach might look something > like this: > > struct M { const char *s; const char **a1; const char **a2; } > message[][2][2] = {{{ > { "Branch %s set ... %s ... %s", &shortname, &origin }, > ... > }},{{ > { "Branch %s set ... %s", &remote, NULL }, > ... > }}}; > > const struct M *m = message[!remote_is_branch][!origin][!rebasing]; > printf_ln(m->s, local, *m->a1, *m->a2); Of course, using NULL in the table like that would crash when dereferenced: *m->a2. It was just an quick example typed on-the-fly. Real code would want to be more careful.