How to get ride of this warning plz? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
9th Jul 2021, 9:17 PM
Ahmed Mahmoud
Ahmed Mahmoud - avatar
4 Answers
+ 1
Either use designated initialiser for the integer fields( like you did for double ones ) of union or put an extra brace to initialise the union field of the struct to initialise the union. Here's the fix 👇 https://code.sololearn.com/cWDml5PTv4wr/?ref=app
10th Jul 2021, 1:04 AM
Arsenic
Arsenic - avatar
+ 1
Thank u. But why i should put braces ?
10th Jul 2021, 4:37 PM
Ahmed Mahmoud
Ahmed Mahmoud - avatar
+ 1
Ahmed Mahmoud because second member of the struct is an union and that is how you initialise an union. Cpp reference says " When initializing an object of struct or union type, the initializer must be a non-empty, brace-enclosed, comma-separated list of initializers for the members " See this for more info about initialising structs and unions 👇 https://en.cppreference.com/w/c/language/struct_initialization.
11th Jul 2021, 12:33 AM
Arsenic
Arsenic - avatar
+ 1
Thank u so much 💙
11th Jul 2021, 6:20 AM
Ahmed Mahmoud
Ahmed Mahmoud - avatar