Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace a non-working #error statement with a working _Static_assert statement #440

Closed
wants to merge 1 commit into from

Conversation

edmund-huber
Copy link
Contributor

The following doesn't work like the author intended:

#define WIFI_INIT_CONFIG_DEFAULT #error Wifi is disabled in config, WIFI_INIT_CONFIG_DEFAULT will not work

Instead of making the compiler print "Wifi is disabled in config,.." and exit, it causes a long confusing error like:

$DELETED/esp-idf/components/esp32/include/esp_wifi.h:138:34: error: stray '#' in program
 #define WIFI_INIT_CONFIG_DEFAULT #error Wifi is disabled in config, WIFI_INIT_CONFIG_DEFAULT will not work
                                  ^
$DELETED/main/./wifi_task.c:37:43: note: in expansion of macro 'WIFI_INIT_CONFIG_DEFAULT'
     wifi_init_config_t wifi_init_config = WIFI_INIT_CONFIG_DEFAULT();
                                           ^
$DELETED/esp-idf/components/esp32/include/esp_wifi.h:138:35: error: 'error' undeclared (first use in this function)
 #define WIFI_INIT_CONFIG_DEFAULT #error Wifi is disabled in config, WIFI_INIT_CONFIG_DEFAULT will not work
                                   ^
$DELETED/main/./wifi_task.c:37:43: note: in expansion of macro 'WIFI_INIT_CONFIG_DEFAULT'
     wifi_init_config_t wifi_init_config = WIFI_INIT_CONFIG_DEFAULT();
                                           ^
$DELETED/esp-idf/components/esp32/include/esp_wifi.h:138:35: note: each undeclared identifier is reported only once for each function it appears in
 #define WIFI_INIT_CONFIG_DEFAULT #error Wifi is disabled in config, WIFI_INIT_CONFIG_DEFAULT will not work
                                   ^
$DELETED/main/./wifi_task.c:37:43: note: in expansion of macro 'WIFI_INIT_CONFIG_DEFAULT'
     wifi_init_config_t wifi_init_config = WIFI_INIT_CONFIG_DEFAULT();
                                           ^
$DELETED/esp-idf/components/esp32/include/esp_wifi.h:138:41: error: expected ',' or ';' before 'Wif'
 #define WIFI_INIT_CONFIG_DEFAULT #error Wifi is disabled in config, WIFI_INIT_CONFIG_DEFAULT will not work
                                         ^
$DELETED/main/./wifi_task.c:37:43: note: in expansion of macro 'WIFI_INIT_CONFIG_DEFAULT'
     wifi_init_config_t wifi_init_config = WIFI_INIT_CONFIG_DEFAULT();

To me, it seems that if anyone includes esp_wifi.h without enabling wifi in the config, then that is an error. I can't imagine a situation where someone wants wifi struct definitions without intending to use wifi, but it's a possibility. Does anyone do that?

@igrr
Copy link
Member

igrr commented Mar 19, 2017

IIRC the idea was to error out only if this macro was actually used in the program. Usage of esp_wifi_* functions would cause linker error, so that's the only remaining definition to check.
Maybe defining WIFI_INIT_CONFIG_DEFAULT to a {0}; _Static_assert(0, "please enable wifi in menuconfig to use esp_wifi.h"); would do the trick?

@edmund-huber
Copy link
Contributor Author

Yeah, it's clear what the intent of the original code was, but my first question I suppose is whether that makes sense at all. Why would one include "wifi.h" if they didn't intend for wifi to be enabled? :P

What you suggested with _Static_assert worked, so maybe we can just do that.

@edmund-huber edmund-huber changed the title don't include esp_wifi.h unless you've enabled wifi in the config replace a non-working #error statement with a working _Static_assert statement Mar 19, 2017
@projectgus projectgus added Status: Pending blocked by some other factor and removed Status: Pending blocked by some other factor labels Mar 22, 2017
igrr pushed a commit that referenced this pull request Mar 23, 2017
igrr pushed a commit that referenced this pull request Mar 23, 2017
@projectgus
Copy link
Contributor

Cherry-picked in 0aab67f, thanks

@projectgus projectgus closed this Mar 24, 2017
@igrr igrr removed the Status: Pending blocked by some other factor label Apr 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants