为什么要使用括号? [英] why use parenthsis ?

查看:140
本文介绍了为什么要使用括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#define BEGIN_MSG_MAP(theClass)\
public:\
BOOL ProcessWindowMessage(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam,LRESULT& lResult,DWORD dwMsgMapID = 0)\
{\
BOOL bHandled = TRUE; \
(hWnd); \
(uMsg); \
(wParam); \
(lParam); \
(lResult); \
(bHandled); \

开关(dwMsgMapID)\
{\
案例0:

#define BEGIN_MSG_MAP(theClass) \
public: \
BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lResult, DWORD dwMsgMapID = 0) \
{ \
BOOL bHandled = TRUE; \
(hWnd); \
(uMsg); \
(wParam); \
(lParam); \
(lResult); \
(bHandled); \

switch(dwMsgMapID) \
{ \
case 0:

推荐答案

我将尝试合成其他三个答案各有重点.

在某些情况下,看似无用的括号对于宏定义的正确性是必需的. («_Superman_»)但是,在突出显示的情况下,它们对预处理器处理代码的方式没有重大影响. (忠实的姜)括号用 documentation 表示,表示由于某种原因而放入了可能由编译器优化的不执行任何操作"表达式. (我)这是为了抑制有关未使用值的编译器警告. (KarstenK)
I''m going to try to synthesis three other answers which each have an important point.

There are situations where seemingly useless parenthesis are necessary for correctness in a macro definition. («_Superman_») In the cases that you have highlighted, however, they have no significant impact on how the preprocessor handles the code. (loyal ginger) The parenthesis are present as documentation to indicate that the "do nothing" expressions that will likely be optimized out by the compiler were put in for a reason. (me) That reason is to suppress compiler warnings about unused values. ( KarstenK )


使编译器对未使用的值保持沉默.

我将BOOL ProcessWindowMessage(HWND/* hWnd */,...

to make the compiler silent about the unused values.

I make that BOOL ProcessWindowMessage(HWND /*hWnd*/,...


通过以下链接-
http://everything2.com/title/Seemingly+useless+parenthesis+in+%2523define+macros [ ^ ]
http://docs.freebsd.org/info/cpp/cpp.info.Macro_Parentheses.html [^ ]
http://www.cprogramming.com/tutorial/cpreprocessor.html [
Go through the following links -
http://everything2.com/title/Seemingly+useless+parenthesis+in+%2523define+macros[^]
http://docs.freebsd.org/info/cpp/cpp.info.Macro_Parentheses.html[^]
http://www.cprogramming.com/tutorial/cpreprocessor.html[^]


这篇关于为什么要使用括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆