Page 1 of 1

ESP_ERROR_CHECK macro syntax

Posted: Fri May 19, 2017 10:00 am
by eyaleb
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

Re: ESP_ERROR_CHECK macro syntax

Posted: Fri May 19, 2017 10:48 am
by ESP_igrr
That semicolon in macro definition was not intentional, thanks for pointing this out.