码迷,mamicode.com
首页 > 系统相关 > 详细

Linux c括号作用域【原创笔记】

时间:2017-07-07 16:34:22      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:static   function   nbsp   int   printf   main   line   ati   定义   

大师指点后,所做的笔记,很感谢一起愿意研究技术的同事,以下不是本人原创,是他分析的成果

#include <stdio.h> #include <time.h> struct lock_class_key { int ck; }; #define mutex_init() do { static struct lock_class_key __key; static int a; printf("macro==>>Line=%d,&__key=0x%p &a=0x%p\n", __LINE__, &__key, &a); } while (0) void __mutex_init() { do { static struct lock_class_key __key1; static int a1; printf("function==>>Line=%d,&__key1=0x%p &a1=0x%p\n", __LINE__, &__key1, &a1); } while (0); } int main(void) { //do { static struct lock_class_key __key; static int a; printf("macro==>>Line=%d,&__key=0x%p &a=0x%p\n", 28, &__key, &a); } while (0);===>宏展开就是这样的,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", 29, &__key, &a); } while (0); //{ static struct lock_class_key __key; static int a; printf("macro==>>Line=%d,&__key=0x%p &a=0x%p\n", 28, &__key, &a); } //{ static struct lock_class_key __key; static int a; printf("macro==>>Line=%d,&__key=0x%p &a=0x%p\n", 29, &__key, &a); } {static int b1;} //=======>这种括号是作用域,一个函数名本来只有一个作用域,但是如果函数里面加了这种,相当于是在两个作用域里面,是允许这样定义的,地址也会不同 //printf("fuck!!\n"); {static int b1;} mutex_init(); mutex_init(); __mutex_init(); __mutex_init(); return (0); } 执行结果: macro==>>Line=37,&__key=0x0x60104c &a=0x0x601050 macro==>>Line=38,&__key=0x0x601054 &a=0x0x601058 function==>>Line=21,&__key1=0x0x601044 &a1=0x0x601048 function==>>Line=21,&__key1=0x0x601044 &a1=0x0x601048

 

Linux c括号作用域【原创笔记】

标签:static   function   nbsp   int   printf   main   line   ati   定义   

原文地址:http://www.cnblogs.com/sky-heaven/p/7132496.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!