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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:05:27+00:00 2026-05-24T00:05:27+00:00

I defined a multi-line macro function using line continuation character \ like the following:

  • 0

I defined a multi-line macro function using line continuation character “\” like the following:

#define SHOWMSG( msg ) \ 
{ \     
    std::ostringstream os; \     
    os << msg; \     
    throw CMyException( os.str(), __LINE__, __FILE__ ); \ 
}

But it could not pass compilation. BTW, I’m using VS2008 compiler. Would you please tell what’s wrong with my aforesaid macro function?

  • 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-05-24T00:05:29+00:00Added an answer on May 24, 2026 at 12:05 am

    The usual method for a multi-statement macro is something like:

    #define SHOWMSG(msg)                                  \
    do {                                                  \
        std::ostringstream os;                            \
        os << msg;                                        \
        throw CMyException(os.str(), __LINE__, __FILE__); \
    } while (0)
    

    Without that, the semicolon following the closing brace can cause syntactic problems, such as:

    if (x)
        SHOWMSG("This is a message");
    else
        // whatever
    

    With your code as it was, this would expand to:

    if (x) {
        std::ostringstream os;
        os << "This is a message";
        throw CMyException(os.str(), __LINE__, __FILE__);
    }
    ;    // on separate line to emphasize that this is separate statement following
         // the block for the if statement.
    else
        // whatever
    

    In this case, the semicolon would form a null statement following the block in the if statement, and the else wouldn’t have an if to match up with.

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

Sidebar

Related Questions

How do I change rowHeight in multi line TableView Cell? #define numberOfLines 2 -
How do you define a multi-line inline template? For example, this grid has an
I've a SDO_GEOMETRY column containing quite large multi polygons , defined like this: INSERT
I defined a Controller to force authentication by using the [Authorize] attribute. When a
ive defined the following and filled it with elements: vector <vector<double> > my_vector; but
I defined the Scheme procedure to return another procedure with 2 parameters : (define
I get an error on line 6 (initialize my_foo to foo_init) of the following
Possible Duplicates: What’s the use of do while(0) when we define a macro? Why
I saw the following question: How to generate a newline in a cpp macro?
What follows is a regular expression I have written to match multi-line pre-processor macros

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.