This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Re: Confusing error for incorrect struct initialization
- From: "lh mouse"<lh_mouse at 126 dot com>
- To: "Mason"<mpeg dot blue at free dot fr>
- Cc: "gcc-help"<gcc-help at gcc dot gnu dot org>
- Date: Sun, 19 Jun 2016 00:42:37 +0800
- Subject: Re: Re: Confusing error for incorrect struct initialization
- Authentication-results: sourceware.org; auth=none
- References: <5764F614 dot 7060108 at free dot fr> <7cebec62 dot 21aed9 dot 155627c508f dot Coremail dot lh_mouse at 126 dot com><5765760A dot 1050200 at free dot fr>
Initializing a `int *` with an `int` has to be permitted. It is making it an error that would be a bug.
The 'initializer element is not constant' error is a different one. In C an object with static (or thread since C11) duration must be initialized with a constant.
They are irrelevant.
------------------
Best regards,
lh_mouse
2016-06-19
-------------------------------------------------------------
åääïMason <mpeg.blue@free.fr>
åéææï2016-06-19 00:25
æääïlh mouse
æéïGCC help
äéïRe: Confusing error for incorrect struct initialization
On 18/06/2016 09:49, lh mouse wrote:
> Mason wrote:
>
>> I opened bug 71552:
>>
>> "Confusing error for incorrect struct initialization"
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71552
>>
>> I don't understand Martin's reply in comment #1.
>>
>> Could someone explain?
>
> Those are GCC implementation details.
>
> In spite that in most cases implicit conversion from an integer
> (except a null pointer constant, of course) to a pointer should be
> considered a casual error, it is however required by the C standard:
>
> Making it an error would make GCC not conform to the standard just
> because C is so broken.
/me scratches head... Making what an error?
The bug is a request to improve an existing error message.
struct xxx { void *p; int a,b,c,d; double x,y; };
struct foo { struct xxx *p; int e,f,g; };
static struct xxx s = { 0 };
struct foo bar = { s }; /*** should be &s ***/
$ gcc-6 -c qoi.c
qoi.c:4:20: error: initializer element is not constant
struct foo bar = { s }; /*** should be &s ***/
^
qoi.c:4:20: note: (near initialization for 'bar.p')
Do you disagree that this is a confusing error message?
Isn't this one better:
incompatible types when initializing type 'struct xxx *' using type 'struct xxx'
Regards.