C利用宏语言(#,##。do…while(0)盛大)

1.使用宏预先定义__FILE__,__FUNCTION__。__LINE__。

#include <stdio.h>
void fun(void)
{
char v1;
short v2;
int v3;
long v4;
printf("v1: %x\n",&v1);
printf("v2: %x\n",&v2);
printf("v3: %x\n",&v3);
printf("v4: %x\n",&v4);
printf("file is :%s,\tfunction is: %s,\tline is :%d\n",__FILE__,__FUNCTION__,__LINE__);
} int main()
{
fun();
printf("file is :%s,\tfunction is: %s,\tline is :%d\n",__FILE__,__FUNCTION__,__LINE__);
return 0;
}

2.#宏字符串化

#include<stdio.h>
#define dprintf(expr) printf("<main>%s=%d\n",#expr,expr)
int main()
{
int x=100;
int y=2; dprintf(x/y);//#expr相当于x/y expr是x/y的运算结果 #是字符串化操作
dprintf(x+y);
dprintf(x+y+2);
return 0;
}

3.##连接字符串

#include<stdio.h>
#define test(x) test ##x
void test1(int a)
{
printf("Test 1 integer: %d \n",a);
}
void test2(char *s)
{
printf("Test 2 String: %s \n",s);
}
int main ()
{
test(1)(100); //test(1)等价于test; test##1等价于test1;##连接字符
test(2)("hello");
return 0;
}

4.do...while(0)宏

#include<stdio.h>
#define hello(str) do{\
printf("Hello:%s\n",str);\
}while(0) int main()
{
int m=0;
if(m)
{ hello("hello true");
}
else
hello("hello false");
system("pause");
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

最新文章

  1. Prime Generator
  2. ASP.NET Core MVC 在linux上的创建及发布
  3. android之数据存储之SQLite
  4. MATLAB中subplot的用法
  5. 基于webpack的前端工程化开发解决方案探索(一):动态生成HTML(转)
  6. [shell基础]——算术运算
  7. jsp中利用checkbox进行批量删除
  8. Winform的窗体美化心酸路
  9. maven解决.lastUpdated maven无法下载jar
  10. WPF 依赖属性与依赖对象
  11. 非UI线程和UI线程通信
  12. scheme代码高亮
  13. oj 小黑熊偷玉米
  14. 前端tab页实例
  15. 超棒的30款JS类库和工具
  16. jQuary学习の三の效果展示
  17. IOCP模型与网络编
  18. vue+betterscrool实现横向弹性滚动
  19. Java垃圾回收(GC)机制详解
  20. CSS3布局之box-flex的使用

热门文章

  1. C# 计算字符串/文件的哈希值(MD5、SHA)
  2. 将Eclipse包括第一3正方形jar包裹Project Export并产生能够执行jar
  3. cocos2dx A* + tiledMap
  4. 用bytecode来看try-catch-finally和return
  5. 关于Relay Log无法自己主动删除的问题(Neither --relay-log nor --relay-log-index were used)
  6. Xamarin.Android中使用android:onClick=&quot;xxx&quot;属性
  7. jQuery的理论基础
  8. coco2dx c++ HTTP实现
  9. 悟道—位IT高管20年的职场心经(读书笔记五)
  10. ubuntu 系统设置bugzilla制