This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Re: Confusing error for incorrect struct initialization


From your point of view no C compiler could be 'good':
---
// 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')
---
// clang 3.3
prog.c:4:20: error: initializing 'struct xxx *' with an expression of incompatible type 'struct xxx'; take the address with &
struct foo bar = { s }; /*** should be &s ***/
                   ^
                   &
prog.c:4:22: warning: missing field 'e' initializer [-Wmissing-field-initializers]
struct foo bar = { s }; /*** should be &s ***/
                     ^
---
// ICC 13.0
example.cpp(4): error: expression must have a constant value
struct foo bar = { s }; /*** should be &s ***/
---
// CL18  (a.k.a. MSVC)
test.c
test.c(4) : error C2099: initializer is not a constant
---

The error suppresses the warning here.
The standard is the standard. The WG14 people don't care what you would think about them and the language. 

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++.


------------------				 
Best regards,
lh_mouse
2016-06-19

-------------------------------------------------------------
åääïMason <mpeg.blue@free.fr>
åéææï2016-06-19 01:42
æääïlh mouse
æéïGCC help
äéïRe: Confusing error for incorrect struct initialization

On 18/06/2016 18:42, lh mouse wrote:

> Initializing a `int *` with an `int` has to be permitted.
> It is making it an error that would be a bug.

The code I'm interested in is:

struct xxx { void *p; int a,b,c,d; double x,y; };
struct foo { struct xxx *p; int e,f,g; };
struct xxx s;
struct foo bar = { s }; /*** should be &s ***/

(I don't see any int pointers there.)

Do you see the error on the last line?
What error message would you expect a good compiler to output?

Regards.




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]