C语言宏替换的几种用法 【转载】
来源:互联网 发布:航天开盘软件 编辑:程序博客网 时间:2024/06/07 05:19
出处:
http://topic.csdn.net/t/20030820/15/2168502.html
①简单宏替换
#defind Pi 3.14159
或
#ifndef __THIS_FILE__
#define __THIS_FILE__ // 用于防止重复包含文件
…… ……
#endif
___________________________
②条件宏替换
#define p(x) printf(x)
…… ……
p("hello!");
→ hello!
___________________________
③字符宏替换(#@)
#define pchar(x) printf("%c\n", #@x)
…… ……
pchar(a);
→ a
___________________________
④字串宏替换(#)
#define pstring(x) printf("%s\n", #x)
…… ……
pstring(hello!);
→ hello!
___________________________
⑤连接宏替换(##)
#define p( n ) printf( "symbol" #n " = %d", symbol##n )
…… ……
int symbol9 = 9;
p( 9 );
→ symbol9=9
#defind Pi 3.14159
或
#ifndef __THIS_FILE__
#define __THIS_FILE__ // 用于防止重复包含文件
…… ……
#endif
___________________________
②条件宏替换
#define p(x) printf(x)
…… ……
p("hello!");
→ hello!
___________________________
③字符宏替换(#@)
#define pchar(x) printf("%c\n", #@x)
…… ……
pchar(a);
→ a
___________________________
④字串宏替换(#)
#define pstring(x) printf("%s\n", #x)
…… ……
pstring(hello!);
→ hello!
___________________________
⑤连接宏替换(##)
#define p( n ) printf( "symbol" #n " = %d", symbol##n )
…… ……
int symbol9 = 9;
p( 9 );
→ symbol9=9
C语言宏收藏
http://blog.csdn.net/tony821224/archive/2008/02/25/2119340.aspx
ANSI C标准中有几个标准预定义宏:__FILE__ __DATE__ __TIME___ __LINE__ 等
__LINE__:在源代码中插入当前源代码行号;
__FILE__:在源文件中插入当前源文件名;
__DATE__:在源文件中插入当前的编译日期
__TIME__:在源文件中插入当前编译时间;
__STDC__:当要求程序严格遵循ANSI C标准时该标识被赋值为1;
__cplusplus:当编写C++程序时该标识符被定义。
阅读全文
0 0
- C语言宏替换的几种用法 【转载】
- C语言宏定义的几种简单用法
- C语言中指针的几种用法
- c语言中typedef的几种用法
- C语言函数指针的几种用法
- c语言中typedef的几种用法
- c语言中typedef的几种用法
- c语言中typedef的几种用法
- c语言常见的几种指针用法
- C语言中指针的几种用法
- c语言中typedef的几种用法
- 【转载】C语言中extern的用法
- 【转载】C语言assert的用法
- 【转载】C语言中#define的用法
- C语言const几种常见用法
- C语言宏替换
- C语言宏替换
- c语言 宏替换的顺序
- dwz封闭当前dailog窗口 【转】
- PHP出现Notice: unserialize(): Error at offset解决方案 【转载】
- wincachegrind 工具
- 启用Xdebug使用WinCacheGrind分析脚本执行时间 【转载】
- 汇编程序:输数字,出字母
- C语言宏替换的几种用法 【转载】
- c中typedef 【转载】
- DWZ select combox 级联中遇到的一个bug
- 数据推送---反ajax comet http扩展
- Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock
- liunx下安装mysql没有初始密码的解决方法【转】
- Linux下C++访问MySQL 【转】
- C/C++连接mysql编译的找不到mysql/mysql.h的问题
- 【转载】PHP register_shutdown_function函数详解