Re: Confusing error for incorrect struct initialization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 18/06/2016 20:01, lh mouse wrote:

> From your point of view no C compiler could be 'good':

Why do you say that? Clang gets it right.

> // gcc 6.1
> test.c:4:20: error: initializer element is not constant
>  struct foo bar = { s }; /*** should be &s ***/
>                     ^
> test.c:4:20: note: (near initialization for 'bar.p')

Confusing error message.

> // clang 3.3
> prog.c:4:20: error: initializing 'struct xxx *' with an expression
> of incompatible type 'struct xxx'; take the address with &

Excellent error message. Exactly what I'm asking for.
They even correctly suggest how to fix the problem!

> // ICC 13.0
> example.cpp(4): error: expression must have a constant value

Confusing.

> ---
> // CL18  (a.k.a. MSVC)
> test.c
> test.c(4) : error C2099: initializer is not a constant

Confusing.

Thanks for providing the 3 other data points.

Obviously I must be missing something, since 3 compilers
produce the same confusing message. Why are they talking
about a non-constant initializer?

> The error suppresses the warning here.

What error suppresses what warning?

Note that the standard does not define "errors" or "warnings".

> The standard is the standard. The WG14 people don't care
> what you would think about them and the language.

A compiler that prints "YUCK!" for every constraint violation
would be a conforming implementation.

I'm saying that gcc's (and icc's, and msvc's) error message
for my test case is confusing and should be improved.

What does that have to do with "the standard"?

> If you truly want to have some error messsages more friendly (thus
> helpful), particularly for your sample code above, you can be happy
> with C++.

Why does C++ help in my test case?

(I hate C++ by the way.)

Regards.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux