PlatformIO Linter Error but then it compiles

FrAxl93
Posts: 4
Joined: Tue Aug 28, 2018 8:49 pm

PlatformIO Linter Error but then it compiles

Postby FrAxl93 » Tue Sep 04, 2018 9:24 pm

Good evening everyone,

I am running the several wi-fi examples for esp32 with platformIO on Atom (MAC). The so called "Linter" which from what I have understood is a sort of intellisense that seeks for errors in the code, tells me that I cannot do the following because "C99 designator is outside aggregate initializer":

Code: Select all

wifi_sta_config_t wifi_AP_conf = {.ssid = WIFI_SSID, .password = WIFI_PASS, };

	wifi_config_t wifi_config = {
        	.sta = wifi_AP_conf,
    };
But then the compiler magically ends with no error whatsoever. May anyone tell me what's happening?

Thanks a lot,
Regards.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: PlatformIO Linter Error but then it compiles

Postby ESP_Angus » Wed Sep 05, 2018 2:13 am

This is a g++ compiler error, I'm surprised the compile still succeeds. Designated initializers of this kind are supported in C99 and newer (C language) but not fully supported in C++.

Here's some more discussion on the platform.io github.

You can either:
  • Rewrite the code so that the string literals WIFI_SSID and WIFI_PASS are not passed in a designated initializer like this (ie write code like strlcpy(wifi_AP_conf.ssid, sWIFI_SSID, sizeof(wifi_AP_conf.ssid))).
  • Move this code to a .c file instead of a .cpp file
  • Find some C++ classes which wrap the WiFi support so you don't need to call the ESP-IDF C API. ESP-IDF does not include a C++ WiFi API, but Arduino does and I believe nkolban may have some as well.

FrAxl93
Posts: 4
Joined: Tue Aug 28, 2018 8:49 pm

Re: PlatformIO Linter Error but then it compiles

Postby FrAxl93 » Wed Sep 05, 2018 7:51 pm

Thanks very much for your reply.

Although I will try all of your other suggestions, I think that the code was compiling because it was in the "main.c" file, but the "Linter" from PlatformIO still analyzed as it was C++ (I guess?).

Thanks a lot,
Regards, Francesco.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: PlatformIO Linter Error but then it compiles

Postby ESP_Angus » Thu Sep 06, 2018 2:30 am

Hi Francesco,
FrAxl93 wrote: Although I will try all of your other suggestions, I think that the code was compiling because it was in the "main.c" file, but the "Linter" from PlatformIO still analyzed as it was C++ (I guess?).
Ah, this seems likely! :) Maybe raise this as a bug with the platform.io folks?

Who is online

Users browsing this forum: Google [Bot] and 66 guests