ESP-IDF 4.4.1: A question about and a possible problem with data storage classes

User avatar
MickPF
Posts: 45
Joined: Tue Apr 03, 2018 8:47 pm

ESP-IDF 4.4.1: A question about and a possible problem with data storage classes

Postby MickPF » Fri Jun 17, 2022 12:43 pm

Hello,

Does the gcc of the ESP-IDF store different storage classes in different address spaces?

Here are the relevant code fragments:

Code: Select all

static const char *name_primitive = "Primitive";
static const char *name_date = "Date";
static const char *name_time = "Time";
static const char *name_sensor_value = "SensorValue";
static const char *name_rssi = "RSSI";

static const struct {
    field_type_t type;
    const char *name;
} field_type[] = {
    { FIELD_TYPE_PRIMITIVE, name_primitive },
    { FIELD_TYPE_TIME, name_time },
    { FIELD_TYPE_DATE, name_date },
    { FIELD_TYPE_SENSOR_VALUE, name_sensor_value },
    { FIELD_TYPE_WIFI_RSSI, name_rssi },
    { FIELD_TYPE_UNKNOWN, NULL }
};
The „standard“ gcc of linux does not generate neither warnings nor error messages for this code. The gcc of the ESP-IDF generates error messages and warnings for the same code:

Code: Select all

settings.c:88:29: error: initializer element is not constant
     { FIELD_TYPE_PRIMITIVE, name_primitive },
                             ^~~~~~~~~~~~~~
settings.c:88:29: note: (near initialization for 'field_type[0].name')
settings.c:88:5: warning: missing initializer for field 'name' of 'const struct <anonymous>' [-Wmissing-field-initializers]
     { FIELD_TYPE_PRIMITIVE, name_primitive },
     ^
settings.c:86:21: note: 'name' declared here
     const char     *name;
                     ^~~~
Who makes mistakes at this place? Me or gcc?
Can somebody help me to solve this problem?

Thanks in advance,
Michael
Nobody is perfect!
My name is NOT Nobody...


Nobody lives forever to correct his mistakes someday in the future, if not right now!
Covid-19 is not responsible for any human failures!

User avatar
gtjoseph
Posts: 92
Joined: Fri Oct 15, 2021 10:55 pm

Re: ESP-IDF 4.4.1: A question about and a possible problem with data storage classes

Postby gtjoseph » Fri Jun 17, 2022 2:01 pm

What version of gcc are you running on your linux host? I tried 8.x, 9.x and 12.x and they all throw the same error. What options are you passing on the linux host.

In any case...

Change

Code: Select all

static const char * name_primitive = "Primitive";
to

Code: Select all

static char * const name_primitive = "Primitive";

See https://stackoverflow.com/questions/890 ... const-char

User avatar
MickPF
Posts: 45
Joined: Tue Apr 03, 2018 8:47 pm

Re: ESP-IDF 4.4.1: A question about and a possible problem with data storage classes

Postby MickPF » Fri Jun 17, 2022 6:31 pm

Hello gtjoseph,

I use gcc-12.1 under openSUSE Tumbleweed without passing any special options to the compiler.

Many thanks for your help, your suggestion works.

Kind Regards,
Michael
Nobody is perfect!
My name is NOT Nobody...


Nobody lives forever to correct his mistakes someday in the future, if not right now!
Covid-19 is not responsible for any human failures!

Who is online

Users browsing this forum: Bing [Bot] and 214 guests