Click here to Skip to main content
12,749,754 members (36,918 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 17 Feb 2011

"if" with no code block parenthesis

, 17 Feb 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Whatever, I agree with you, it would be worse in C / C++ code using macros.Suppose you got a multiline macro like this:#define some_macro \ do_something_1(); \ do_something_2();And using this macro without parenthesis:if(...) some_macro;orfor(...) ...
Whatever, I agree with you, it would be worse in C / C++ code using macros.
Suppose you got a multiline macro like this:

#define some_macro \
    do_something_1(); \

And using this macro without parenthesis:


Only do_something_1() will be executed internally in those if / for blocks and do_something_2() is treated as an external statement.
So I'm used to add a pair of { } there, and even surround multiline macros with them in C / C++ like:
#define some_macro \
    { \
        do_something_1(); \
        do_something_2(); \

That would be better I think.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

China China
Video game player & creator; Hardware geek & maker.

You may also be interested in...

Comments and Discussions

GeneralStill evil, since "if (whatever) some_macro; else something_... Pin
supercat918-Feb-11 7:29
membersupercat918-Feb-11 7:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170215.1 | Last Updated 18 Feb 2011
Article Copyright 2011 by paladin_t
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid