Re: [PATCH] cli: use designated initializers for opt desc

Subject: Re: [PATCH] cli: use designated initializers for opt desc

Date: Sun, 01 Oct 2017 21:45:01 +0300

To: Jani Nikula, notmuch@notmuchmail.org

Cc:

From: Tomi Ollila


On Sun, Oct 01 2017, Jani Nikula wrote:

> On Sun, 01 Oct 2017, Tomi Ollila <tomi.ollila@iki.fi> wrote:
>>
>> Good stuff. It just doesn't longer compile on older compilers (so some
>> note on commit message should be added):
>
> Does this on top fix it? I used the unnamed struct just for clarity, and
> it doesn't serve a functional purpose.

Yes it does!

(output is noisy, but so is it with gcc 4.8.5 which I just tested to work)

Thanks,

Tomi

>
> BR,
> Jani.
>
> diff --git a/command-line-arguments.h b/command-line-arguments.h
> index 97134ad535ee..799b7fef3f65 100644
> --- a/command-line-arguments.h
> +++ b/command-line-arguments.h
> @@ -16,15 +16,13 @@ typedef struct notmuch_keyword {
>  /* Describe one option. */
>  typedef struct notmuch_opt_desc {
>      /* One and only one of these must be set. */
> -    struct {
> -	const struct notmuch_opt_desc *opt_inherit;
> -	notmuch_bool_t *opt_bool;
> -	int *opt_int;
> -	int *opt_keyword;
> -	int *opt_flags;
> -	const char **opt_string;
> -	const char **opt_position;
> -    };
> +    const struct notmuch_opt_desc *opt_inherit;
> +    notmuch_bool_t *opt_bool;
> +    int *opt_int;
> +    int *opt_keyword;
> +    int *opt_flags;
> +    const char **opt_string;
> +    const char **opt_position;
>  
>      /* Must be set except for opt_inherit and opt_position. */
>      const char *name;
> --
>
>>
>> CC  -g -O2 notmuch.o
>> notmuch.c:53: error: unknown field ‘opt_bool’ specified in initializer
>> notmuch.c:53: warning: missing braces around initializer
>> notmuch.c:53: warning: (near initialization for
>> ‘notmuch_shared_options[0].<anonymous>’)
>> notmuch.c:53: warning: initialization from incompatible pointer type
>> notmuch.c:53: warning: missing initializer
>> notmuch.c:53: warning: (near initialization for
>> ‘notmuch_shared_options[0].<anonymous>.opt_bool’)
>> notmuch.c:54: error: unknown field ‘opt_bool’ specified in initializer
>> notmuch.c:54: warning: initialization from incompatible pointer type
>> notmuch.c:54: warning: missing initializer
>> notmuch.c:54: warning: (near initialization for
>> ‘notmuch_shared_options[1].<anonymous>.opt_bool’)
>> notmuch.c:55: error: unknown field ‘opt_string’ specified in initializer
>> notmuch.c:55: warning: initialization from incompatible pointer type
>> notmuch.c:55: warning: missing initializer
>> notmuch.c:55: warning: (near initialization for
>> ‘notmuch_shared_options[2].<anonymous>.opt_bool’)
>> notmuch.c:56: warning: missing initializer
>> notmuch.c:56: warning: (near initialization for
>> ‘notmuch_shared_options[3].<anonymous>’)
>> notmuch.c: In function ‘notmuch_minimal_options’:
>> notmuch.c:85: error: unknown field ‘opt_inherit’ specified in initializer
>> notmuch.c:85: warning: missing braces around initializer
>> notmuch.c:85: warning: (near initialization for ‘options[0].<anonymous>’)
>> notmuch.c:85: warning: missing initializer
>> notmuch.c:85: warning: (near initialization for
>> ‘options[0].<anonymous>.opt_bool’)
>> notmuch.c:86: warning: missing initializer
>> notmuch.c:86: warning: (near initialization for ‘options[1].<anonymous>’)
>> notmuch.c: In function ‘main’:
>> notmuch.c:414: error: unknown field ‘opt_string’ specified in initializer
>> notmuch.c:414: warning: missing braces around initializer
>> notmuch.c:414: warning: (near initialization for ‘options[0].<anonymous>’)
>> notmuch.c:414: warning: initialization from incompatible pointer type
>> notmuch.c:414: warning: missing initializer
>> notmuch.c:414: warning: (near initialization for
>> ‘options[0].<anonymous>.opt_bool’)
>> notmuch.c:415: error: unknown field ‘opt_inherit’ specified in initializer
>> notmuch.c:415: warning: missing initializer
>> notmuch.c:415: warning: (near initialization for
>> ‘options[1].<anonymous>.opt_bool’)
>> notmuch.c:416: warning: missing initializer
>> notmuch.c:416: warning: (near initialization for ‘options[2].<anonymous>’)
>> make: *** [notmuch.o] Error 1
>>
>> gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC) 
>>
>> This was on Scientific Linux 6.2 -- will test on CentOS 7 (which IIRC has
>> gcc 4.8) container soon...
>>
>>
>> Tomi
>> _______________________________________________
>> notmuch mailing list
>> notmuch@notmuchmail.org
>> https://notmuchmail.org/mailman/listinfo/notmuch
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch
_______________________________________________
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch

Thread: