"Thinkinginc++" 47, about the use of macros, explore the disadvantages of using macros

Source: Internet
Author: User

/*** book: "thinkinginc++" * Function: about the use of macros, explore the disadvantages of using macros * Time: September 11, 2014 07:50:54* Author: cutter_point*/#include ". /require.h "#include <fstream>using namespace std;//here is to use BAND (x) instead of the following string of functions # define BAND (x) (((x) >5 && (x) <10)? (x): 0) int main () {    ofstream out ("Macro.txt");    Assure (out, "macro.txt");    for (int i=4; i < one; ++i)    {        int a=i;        out<< "a=" <<a<<endl<< ' t ';        Be careful here, remember to use the macro instead of the result expansion should be like this        //(((++a) >5 && (++a) <10)? (++a): 0) Call three times ++a,        //OK, once the code is executed, the problem is immediately reflected        out<< "BAND (++a) =" <<band (++a) <<endl;        out<< "\ a=" <<a<<endl;    }    return 0;} /* Execution Result: a= 4BAND (++a) =0 a=5a= 5BAND (++a) =8 a=8a= 6BAND (++a) =9 a=9a= 7BAND (++a) =10 a=10a= 8BAND (++a) =0 a=10a= 9BAND (++a) =0 A =11a= 10BAND (++a) =0 a=12*/

"Thinkinginc++" 47, about the use of macros, explore the disadvantages of using macros

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.