4

I have declared 2 structure :

typedef struct
{
  int a;
  int b;
}ma_Struct;

typedef struct
{
  int x;
  ma_Struct tab[2];
}maStruct_2;

The goal is to initialise an instance of maStruct_2 so what i did is:

int main()
{
 ma_Struct elm1={0,1};
 ma_Struct elm2={1,2};

 ma_Struct tab_Elm[2]={elm1,elm2};
 maStruct_2 maStruct_2_Instance={1,tab_Elm};

return 0;
}

but i got the warning missing braces around initializer,i tried this syntax

maStruct_2 maStruct_2_Instance={1,{tab_Elm}};

but the same warning appears. Could you please help me

1 Answer 1

1

In C, you cannot initialize an array by using another array name as initializer.

So the error has nothing to do with structs as such, nor does it have anything to do with scope or constant expressions.

Fix your code like this:

maStruct_2 maStruct_2_Instance = {1, {elm1, elm2}};
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.