博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux c括号作用域【原创笔记】
阅读量:7108 次
发布时间:2019-06-28

本文共 1811 字,大约阅读时间需要 6 分钟。

大师指点后,所做的笔记,很感谢一起愿意研究技术的同事,以下不是本人原创,是他分析的成果 #include 
#include
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=0x0x601050macro==>>Line=38,&__key=0x0x601054 &a=0x0x601058function==>>Line=21,&__key1=0x0x601044 &a1=0x0x601048function==>>Line=21,&__key1=0x0x601044 &a1=0x0x601048

 

【作者】
【出处】
【博客园】
【新浪博客】
【知乎】
【我的作品---旋转倒立摆】
【我的作品---自平衡自动循迹车】
【新浪微博】 张昺华--sky
【twitter】 @sky2030_
【facebook】 张昺华 zhangbinghua
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
你可能感兴趣的文章
Windows7 自动更新时遇到故障
查看>>
我的友情链接
查看>>
spring加载配置属性文件(properties)
查看>>
redis设置
查看>>
android的唯一性
查看>>
深入理解java虚拟机——OutOfMemoryError异常
查看>>
《The way to go》中文版
查看>>
上万个任务让你hold不住?
查看>>
jQuery设置元素是否显示
查看>>
MySQL数据库的基本概述和基本应用
查看>>
samsung Galaxy S3 i9300 获得root权限
查看>>
.NET EasyUI datebox添加清空功能
查看>>
查看Android手机保存的WIFI无线密码
查看>>
「深入 Exchange 2013」09 证书
查看>>
FireFox不支持event解决方法
查看>>
Linux系统生成随机密码的10种方法
查看>>
湖南省委短信平台改造方案
查看>>
我对51CTO的心得
查看>>
mysql基本操作-表结构的调整与索引
查看>>
我的友情链接
查看>>