Confusing error for incorrect struct initialization

lh mouse lh_mouse@126.com
Sat Jun 18 16:42:00 GMT 2016


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.





More information about the Gcc-help mailing list