Linux C-Bracket Scope "original notes"

Source: Internet
Author: User

After the master guidance, the notes, very grateful for a colleague willing to study technology, the following is not my original, is his analysis of the results

#include <stdio.h>#include<time.h>structLock_class_key {intck;};#defineMutex_init () Do { Static structLock_class_key __key; Static intA; printf ("macro==>>line=%d,&__key=0x%p &a=0x%p\n", __line__, &__key, &a); } while(0)void__mutex_init () { Do { Static structLock_class_key __key1; Static intA1; printf ("function==>>line=%d,&__key1=0x%p &a1=0x%p\n", __line__, &__key1, &A1); } while(0); }intMainvoid){//Do {static struct lock_class_key __key; static int A; printf ("Macro==>>line=%d,&__key=0x%p &a=0x%p\n" , &__key, &a); } while (0);===> macro expansion is like this, GCC-E-o test.i test.c//Do {static struct lock_class_key __key; static int A; printf ("Macro==>>line=%d,&__key=0x%p &a=0x%p\n" , &__key, &a); } while (0);//{static struct lock_class_key __key; static int A; printf ("Macro==>>line=%d,&__key=0x%p &a=0x%p\n", &__key, &a); }//{static struct lock_class_key __key; static int A; printf ("Macro==>>line=%d,&__key=0x%p &a=0x%p\n", &__key, &a); } {Static intB1;} =======> This type of parenthesis is scoped, a function name has only one scope, but if this is added to the functions, which is equivalent to two scopes, it is allowed to be defined, and the address will be different .//printf ("fuck!! \ n ");{Static intB1;} Mutex_init (); Mutex_init (); __mutex_init (); __mutex_init (); return(0);} Executive Result: Macro==>>line=Panax Notoginseng, &__key=0x0x60104c &a=0x0x601050macro==>>line= -, &__key=0x0x601054 &a=0x0x601058function==>>line= +, &__key1=0x0x601044 &a1=0x0x601048function==>>line= +, &__key1=0x0x601044 &a1=0x0x601048

Linux C-Bracket Scope "original notes"

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.