宏函数操作符 可变参数操作


#define  _CRT_SECURE_NO_WARNINGS 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


//# ##
//#  如果写在宏函数体的内部, # 表示生成一个字符串。
#define STR(s) \
       #s


//## 如果卸载宏函数体的内部, ## 表示拼接两个C token
#define A(first, second)	first##second


#define G(a)  g_##a

#define ITCAST(a)  itcast_##a


#define SHOW_LIST(...) \
	printf(#__VA_ARGS__)


#define compare(test, ...) \
	(test) ? (#test) : printf(#__VA_ARGS__);

int main(int argc, char **argv)
{
	printf(STR(main(10,20,30)));

	printf("\n");

	A(printf, ("%s\n", "abc"););
	printf("%s\n", "abc");

	int G(value) = 10; // int g_value = 10;

	int ITCAST(value2) = 20;// int itcast_value2 = 20;

	printf("000000\n");



	SHOW_LIST(dsadsasa, 321321, dsadas, 32132);

	printf("\n");


	int aa = 10;
	int bb = 20;

	compare((aa > bb), a is little than b);

	return 0;
}


#define  _CRT_SECURE_NO_WARNINGS 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>



#define DEBUG(format, ...) \
do {  \
	printf("[DEBUG][%s:%d][%s:%s]"format, __FUNCTION__, __LINE__, __DATE__, __TIME__, ##__VA_ARGS__); \
}  while (0)

#define ERROR(format, ...) \
do { \
	printf("[ERROR][%s:%d][%s:%s]"format, __FUNCTION__, __LINE__, __DATE__, __TIME__, ##__VA_ARGS__); \
} while (0)

int main(int argc, char **argv)
{
	

	char *p = NULL;

	p = (char*)malloc(100);
	if (p == NULL) {
		ERROR("p==NULL\n");  //error p == NULL
		//printf("error,  p == NULL \n");
		return -1;
	}

	int a = 10;

	DEBUG("p malloc succ %d, %d\n", a, a); //debug, p malloc succ!
	//printf("debug, p malloc succ!\n");

	return 0;
}








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值