ESP_ERROR_CHECK macro syntax

eyaleb
Posts: 31
Joined: Sun May 14, 2017 6:54 am

ESP_ERROR_CHECK macro syntax

Postby eyaleb » Fri May 19, 2017 10:00 am

Do we have a syntax style document for the IDF? The following may seem like a nitpick but...

Looking at the definition of the ESP_ERROR_CHECK macro in components/esp32/include/esp_err.h, I notice that it includes a final semicolon. Traditionally this is not done, so as to not break statements like this:

Code: Select all

if (some_condition)
    ESP_ERROR_CHECK (some_func());
else
    ESP_ERROR_CHECK (some_other_func());
The current syntax (in master) leads to

Code: Select all

if (some_condition)
    do {
        esp_err_t rc = (some_func());
        ...
    } while(0);;
else
    do {
        esp_err_t rc = (some_other_func());
        ...
    } while(0);;
which is a syntax error (note the two semicolons)

Code: Select all

   error: 'else' without a previous 'if'
One can get around this with:

Code: Select all

if (some_condition)
    ESP_ERROR_CHECK (some_func())
else
    ESP_ERROR_CHECK (some_other_func())
But most people put a final semicolon regardless of the need, following a standard function call syntax. In the current tree I see a final semicolon is present in each case (where it is redundant with the current macro).

Fixing this will break programs that do not have a final semicolon in the invocation.

cheers

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: ESP_ERROR_CHECK macro syntax

Postby ESP_igrr » Fri May 19, 2017 10:48 am

That semicolon in macro definition was not intentional, thanks for pointing this out.

Who is online

Users browsing this forum: No registered users and 84 guests