Composite expression in brackets of gun c Extension

Source: Internet
Author: User

In the linux world, you may have seen many unknown structures and statements. You may not know their purposes. For example, the composite expressions in parentheses are as follows: [cpp] # include <stdio. h> # define max (x, y) \ <SPAN style = "COLOR: # ff0000"> ({int z; \ if (x> y) z = x; \ else z = y; \ z ;\}) </SPAN> int main (int argc, char ** argv) {max (); return 0 ;} # include <stdio. h ># define max (x, y) \ ({int z; \ if (x> y) z = x; \ else z = y; \ z ;\}) int main (int argc, char ** argv) {max (3, 5); return 0;} Of course, this can be programmed in gun c, Because it is an extension of gun c, the format is ({content}), which is common in macro definition. The entire content uses the last sentence as the return value, that is, the max macro returns an int value, this value is the value of z. If you do not know the types of x and y in advance, you can rest assured that typeof can help you solve this problem. There are a lot of such structures in linux code. Don't know what's going on!

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.