Possible Duplicate:
Do-While and if-else statements in C/C++ macros
gcc (GCC) 4.7.2
c89
Hello,
I have the following function-like macro and just wondering what is the preferred usage when using across multiple lines. It it better to use curly braces or do..while(0) loop.
Normally I use a do..while(0) for everything. But I have seen some projects where they just use the curly braces, and I am not sure which one would be better.
do..while
#define DSO_ERROR(msg, res_handle_module, mem_pool, size)   do {        \
        char *dso_error = apr_palloc((apr_pool_t*)mem_pool, size);      \
        apr_dso_error((apr_dso_handle_t*)res_handle_module, (char*)dso_error, (apr_size_t)size); \
        LOG_ERR("%s dso error %s", (char*)msg, dso_error);              \
        goto dso_failure;                                               \
    } while(0); 
curly braces
#define DSO_ERROR(msg, res_handle_module, mem_pool, size) {             \
        char *dso_error = apr_palloc((apr_pool_t*)mem_pool, size);      \
        apr_dso_error((apr_dso_handle_t*)res_handle_module, (char*)dso_error, (apr_size_t)size); \
        LOG_ERR("%s dso error %s", (char*)msg, dso_error);              \
        goto dso_failure;                                               \
    }
The only difference is that a semi-colon will be preset on the do..while loop and not on the curly braces.
Many thanks for any suggestions,
 
     
     
     
    