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
esp_err.h ESP_ERROR_CHECK definition error (IDFGH-12787) #13766
Comments
How are you actually using |
Yes, I see I also used ESP_ERROR_CHECK() in a header file. I am going to remove that and test again. |
I removed it from the header file, however the errors continue:
|
Can you please show the piece of code where you are actually using this macro? |
Here is an extract of the code where ESP_ERROR_CHECK is used:
|
Hello. ESP_ERROR_CHECK needs to be inside of a function ( This is not valid: #if !defined(bus_handle)
i2c_master_bus_handle_t bus_handle;
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_mst_config, &bus_handle));
#endif You need to put Tbh any function call should be done from an another function, regardless if it's wrapped in ESP_ERROR_CHECK macro or not, initializer elements for global variables should be constant as far as I understand, it shouldn't compile anyway. |
Yes as @adokitkat says, you cannot simply call functions/run code "statically" like that in C. Closing this one as there doesnt seem to be any IDF related issues (not related to For generic questions which are not related to ESP-IDF you can also try our forum |
Thank you both! |
Answers checklist.
IDF version.
ESP-IDF v5.4-dev-78-gd4cd437ede-dirty
Operating System used.
Linux
How did you build your project?
Command line with CMake
If you are using Windows, please specify command line type.
None
What is the expected behavior?
I expected the build not showing errors from esp-idf components parts.
What is the actual behavior?
ninja output at end of build:
/home/paulsk/esp/esp-idf/components/esp_common/include/esp_err.h:115:28: error: expected identifier or '(' before 'do'
115 | #define ESP_ERROR_CHECK(x) do {
| ^~
/home/paulsk/esp/temphum_master/main/main_master_v1.h:25:1: note: in expansion of macro 'ESP_ERROR_CHECK'
25 | ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_mst_config, &bus_handle));
| ^~~~~~~~~~~~~~~
/home/paulsk/esp/esp-idf/components/esp_common/include/esp_err.h:121:7: error: expected identifier or '(' before 'while'
121 | } while(0)
| ^~~~~
/home/paulsk/esp/temphum_master/main/main_master_v1.h:25:1: note: in expansion of macro 'ESP_ERROR_CHECK'
25 | ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_mst_config, &bus_handle));
| ^~~~~~~~~~~~~~~
/home/paulsk/esp/esp-idf/components/esp_common/include/esp_err.h:115:28: error: expected identifier or '(' before 'do'
115 | #define ESP_ERROR_CHECK(x) do {
| ^~
/home/paulsk/esp/temphum_master/main/main_master_v1.h:34:1: note: in expansion of macro 'ESP_ERROR_CHECK'
34 | ESP_ERROR_CHECK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
| ^~~~~~~~~~~~~~~
/home/paulsk/esp/esp-idf/components/esp_common/include/esp_err.h:121:7: error: expected identifier or '(' before 'while'
121 | } while(0)
| ^~~~~
/home/paulsk/esp/temphum_master/main/main_master_v1.h:34:1: note: in expansion of macro 'ESP_ERROR_CHECK'
34 | ESP_ERROR_CHECK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
Steps to reproduce.
Build or installation Logs.
More Information.
This is the part of esp_err.h containing the macro definition:
/**
*/
#ifdef NDEBUG
#define ESP_ERROR_CHECK(x) do {
esp_err_t err_rc_ = (x);
(void) sizeof(err_rc_);
} while(0)
#elif defined(CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT)
#define ESP_ERROR_CHECK(x) do {
esp_err_t err_rc_ = (x);
if (unlikely(err_rc_ != ESP_OK)) {
abort();
}
} while(0)
#else
#define ESP_ERROR_CHECK(x) do {
esp_err_t err_rc_ = (x);
if (unlikely(err_rc_ != ESP_OK)) {
esp_error_check_failed(err_rc, FILE, LINE,
__ASSERT_FUNC, #x);
}
} while(0)
#endif
The text was updated successfully, but these errors were encountered: