常用的预定义和预编译

1)#define 的符号用法
	##连接
	#define con(x,y) x##y
	n=con(123,456)	->	n=123456	字符串也是类似

	#@转字符
	#define tochar(x) #@x 		x不超过3位
	char a=tochar(1)	->	a='1'

	#转字符串
	#define tostring(x)	#x
	char *str =tostring(12345)	->str="12345"

	\行继续

	代表不换行

	__VA_ARGS__
	接受不定数量的参数

	#define longargv(...) fprintf(stderr,__VA_ARGS__)

	longargv("%s:%d:","hello",10)	->fprintf(stderr,"%s:%d:","hello",10)



3)预编译条件分析	

	#if 0

		code

	#endif	

	类似于 /* code */

	实例:
	 int a=0;

    #if 0		//为0就不编译里面的code

        a=10;

    #endif

    printf("%d\n",a);

	实例2:
	#define BULL 0

int main()

{
        char ch='a';

    #if BULL			//非0为真
        ch='c';
    #else
        ch='b';
    #endif

    printf("%c\n",ch);

return 1;
}

实例3:
#define BULL 0

int main()

{
        char ch='a';

    #if _BULL			//如果BULL被#define定义过就为真
        ch='c';
    #else
        ch='b';
    #endif

    printf("%c\n",ch);

return 1;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值