I get error constant expression required

2019-08-16 12:42发布

I'm using this inside a Header File:

typedef struct
{
 int DefaultValue;

}SetValues;

extern volatile SetValues XronosTrofodosias;

And this inside my Source file:

volatile SetValues XronosTrofodosias;

int  *DefaultValuesWaterSubMenu[]={XronosTrofodosias.DefaultValue};

Why i get this error? How can i fix that?

Here is my Real String

int  *DefaultValuesWaterSubMenu[]={XronosTrofodosias.DefaultValue,XronosAdranias.DefaultValue,XronosTrofodosiasHighTemp.DefaultValue,Xronos1hsRipsis.DefaultValue,Xronos2hsRipsis.DefaultValue,Kathisterisi2hsRipsis.DefaultValue,Energopoihsi2hsRipsis.DefaultValue,0,XronosAnemistiraOn.DefaultValue,XronosAnemistiraOff.DefaultValue,AnamoniAnemistira.DefaultValue,AdraniaAisthitiraFloagas.DefaultValue,StrofesAnafleksis.DefaultValue,AnoOrioAisthitiraFloagas.DefaultValue,KatoOrioAisthitiraFloagas.DefaultValue,EnergopohisiAisthitiriou.DefaultValue,OrioThermokrasiasKausaerion.DefaultValue,OrioThermokrasiasNerou.DefaultValue,KathisterisiAnemistira.DefaultValue,EnergopoihsiEksanemismou.DefaultValue,DiarkiaEksanemismou.DefaultValue,0,StrofesKausisAnemistira.DefaultValue,ThermokrasiaEkkinisisKikloforiti.DefaultValue,AnoOrioThermokrasiasNerou.DefaultValue,KatoOrioThermokrasiasNerou.DefaultValue,AnoOrioThermokrasiasKausaerion.DefaultValue,KatoOrioThermokrasiasKausaerion.DefaultValue};

标签: c mplab
1条回答
Juvenile、少年°
2楼-- · 2019-08-16 13:27

You are trying to initialize the array with values which are unknown at compile time which makes them non-constant.

Also the array contains elements of type int* and you are trying to initialize it with values of type int.

A fix to the first problem would be to initialize each element separately:

DefaultValuesWaterSubMenu[0] = ....;

A fix to the second porblem would be to change the array to contain int values

int DefaultValuesWaterSubMenu[10];

DefaultValuesWaterSubMenu[0] = XronosTrofodosias.DefaultValue;

Or

DefaultValuesWaterSubMenu[0] = &XronosTrofodosias.DefaultValue;
查看更多
登录 后发表回答