Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8954637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:21:10+00:00 2026-06-15T14:21:10+00:00

Possible Duplicate: Do-While and if-else statements in C/C++ macros gcc (GCC) 4.7.2 c89 Hello,

  • 0

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,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:21:11+00:00Added an answer on June 15, 2026 at 2:21 pm

    The curly brace version will break usage like this:

    if( foo )
      DSO_ERROR("Foo occured!", my_module, the_pool, 4711);
    else
      printf("All is well, there is no foo\n");
    

    which is the very reason for the do ... while(0) construct. So that seems worth avoiding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Why are there sometimes meaningless do/while and if/else statements in C/C++ macros?
Possible Duplicate: Why are there sometimes meaningless do/while and if/else statements in C/C++ macros?
Possible Duplicate: Why are there sometimes meaningless do/while and if/else statements in C/C++ macros?
Possible Duplicate: Why are there sometimes meaningless do/while and if/else statements in C/C++ macros?
Possible Duplicates: Do-While and if-else statements in C/C++ macros do { … } while
Possible Duplicates: Why are there sometimes meaningless do/while and if/else statements in C/C++ macros?
Possible Duplicate: How many lines of code should a function/procedure/method have? I would like
Possible Duplicates: Why are there sometimes meaningless do/while and if/else statements in C/C++ macros?
Possible Duplicate: Are do-while-false loops common? Is there a reason to have code like:
Possible Duplicate: Why avoid while loops? I am trying to learn Python by following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.