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 745191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T09:03:58+00:00 2026-05-14T09:03:58+00:00

While reading codes of my group project, I come across many DEFINEs, and some

  • 0

While reading codes of my group project, I come across many DEFINEs, and some of them seems strange. To generalize it, please look at the following 2 examples.

Example 1:

#define SNPRINTF(dst, fmt, arg...)  snprintf(dst, sizeof(dst), fmt, ##arg)

what does “##” means in this circumstance? I’ve tried to delete both of them, and write codes like “char buf[1024]; SNPRINTF(buf,”%s,%s”,”abcd”,”efg”);” which produced the same result. So “##” seems no use and no harm to me.

Example 2:

#define CLOSE(fd)   do  {   \
        if (-1 != (fd)) {   \
                    close(fd);  \
                    (fd)    = -1;   \
                }   \
} while (0)

Necessary to stuff the inner code to the do{}while(0) statement? What’s the use?

  • 1 1 Answer
  • 2 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-05-14T09:03:59+00:00Added an answer on May 14, 2026 at 9:03 am

    The ... identify a variadic macro per the C99 standard. The token to indicate expansion of “all remaining argument” in the right hand side, per the standard, is __VA_ARGS__ — I imagine you’re using some C compiler with a non-standard extension that allows the different forms you’re using (## is the preprocessor token-pasting operator, but I don’t see how that applies here).

    The second form is a classic trick (older even than C89) to ensure a ; after the macro behaves correctly, an else after it doesn’t bind to the wrong if, and so on. Basically, wrapping the multiple and conditional statements needed in that do…while safely “nests” them inside a block that requires a semicolon afterwards, syntactically “just as if” the macro invocation was instead a function call.

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

Sidebar

Related Questions

I am new to Python. While reading some code, I come across what is
I have come across with this syntax while reading some others code Map<String, String>
While reading a book on C#, I have come across code that uses the
While reading a code I came across, the following definition and initialization of a
I am new to vbscript and while reading i found some code as Do
recently, while reading former's code in my current project, I encounter the problems below:
I came across lot of flags while reading someone else code, if (condition1) var1
I get confused with some terms while reading MSDN documents and code samples. What
While reading through javascript codes I've been seeing the ! operator used for non
I found this while reading some source code. #define MACRO(x) if((void) 0, (x)); else

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.