Using Parentheses in Define Preprocessor Statements

前端 未结 4 1637
灰色年华
灰色年华 2020-12-06 13:59

So I was wondering when is to use

 #define xxx (yyy)

vs

 #define xxx  yyy

My project includes a files tha

4条回答
  •  借酒劲吻你
    2020-12-06 14:24

    An important thing to remember is that the preprocessor simply expands macros. For example, if you had the following lines:

    #define AD0_COMPARETIME_1    (AD0_ADMD_CT)
    #define AD0_COMPARETIME_2    AD0_ADMD_CT
    
    num_1 = AD0_COMPARETIME_1;
    num_2 = AD0_COMPARETIME_2;
    

    After the first expansion you'd have this:

    num_1 = (AD0_ADMD_CT);
    num_2 = AD0_ADMD_CT;
    

    And after the second expansion you'd have this:

    num_1 = ((IO_AD1.ADMD.bit.CT));
    num_2 = (IO_AD1.ADMD.bit.CT);
    

    A problem may arise, as stated in other answers, when an expression is expanded.

提交回复
热议问题