1. 打印变量名及其值

#define Inquire(var, mode)  fprintf(stdout, #var" = "#mode". \n", var)
// Usage
PSTR $PATH$ = "C:\\windows\\system32;.";
Inquire($PATH$, "%s");
// Output
// $PATH$ = "c:\windows\system32;.".

2.可变参宏的使用

void _Log(const char *format, ...);
#define Log(format, ...) _Log(format, ##__VA_ARGS__) //__VA_ARGS__是C99提供的特性可变宏参数,##用于当没有多余参数时删除format之后的','避免编译错误

#include <stdarg.h>
#include <stdio.h> static int i = ;
void _Log(const char *format, ...){
  va_list list = ; // NULL
  va_start(list, format);
  {
    fprintf(stdout, "==Log %d== ", ++i);
    vfprintf(stdout, format, list);
    fprintf(stdout, "\n");
  }
  va_end(list);
}

3.断言

void _Assert(const char *info, const char *func, int line);
#define Assert(x) if(!(x)) _Assert("断言失败!文件:" __FILE__ ",函数:%s,行:%d--\"" #x "\".", __FUNCTION__, __LINE__)

#include <stdio.h> void _Assert(const char *info, const char *func, int line){
fprintf(stderr, info, func, line);
abort();
}

最新文章

  1. Excel&mdash;&mdash;MATCH函数
  2. 【leetcode】Roman to Integer
  3. DataTable Linq Example
  4. strace命令(收集整理,常看常新)
  5. zipline tradingcalendar
  6. cmd命令查看端口和进程信息
  7. sharepoint2013 新建母板页 新建页面布局 关联母板页和页面布局
  8. 新一批电子商务解决方案和企业管理应用加入 VM Depot 中国站点
  9. Oracle百问百答(二)
  10. HTTP数据包头解析(简单清楚)
  11. Objective-C Effective 技巧
  12. ELK系列~nxlog实现多位置文件的收集
  13. struts2 添加请求后缀的3种方式
  14. Intellij Idea 2018常用快捷键总结
  15. (九)逻辑运算,order by,desc
  16. Django Model模型的实战操作笔记
  17. Pycharm快捷键大全(windows + Mac)
  18. git difftool和mergetool图形化
  19. TP5 首页导航一级和二级分类
  20. nio入门教程

热门文章

  1. [AH2017/HNOI2017]礼物(FFT)
  2. NOIP2013花匠(波动序列)
  3. CodeForces - 95B(DFS)
  4. web字体的设置
  5. 工厂方法模式(Factory Method)和抽象工厂模式(Abstact Factory)
  6. QML学习笔记(四)-TabView-竖直方向
  7. JS判断手机还是电脑访问网站
  8. 向redis中添加删除list列表
  9. template specifiers not specified in declaration of ‘template&lt;class Key&gt; class hash’
  10. session/cookie/token