0

I have definition and declaration of constant int:

a.h

extern const int w ;

a.c

const int w = LV_HOR_RES_MAX / 2

Trying to use it in another c file:

b.c

typedef struct picLabing
    {
        int width;
    } aaa;

typedef struct {
    aaa  temperatures;
}settings_typ;

settings_typ a =
{
 .temperatures = { .width = w },
}

Got error while build:

Error    initializer element is not constant 

Why I'm getting this error? According to my understanding w is declared as constant .

Everything works fine when I define and declare w in the same b.c file. Why?

vico
  • 15,367
  • 39
  • 141
  • 262
  • Related: https://stackoverflow.com/questions/3025050/error-initializer-element-is-not-constant-when-trying-to-initialize-variable-w – jarmod Dec 01 '21 at 16:22

0 Answers0