Page 1 of 1

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

Posted: Fri Jun 17, 2022 12:43 pm
by MickPF
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

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

Posted: Fri Jun 17, 2022 2:01 pm
by gtjoseph
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

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

Posted: Fri Jun 17, 2022 6:31 pm
by MickPF
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