经常手动敲打字符串,显示才显示出变量名,比如:
printf("a = %d\n", a);
现在,使用宏定义
#define my_int(n) printf(#n" = %d\n", n)
就搞定了。
示例代码:
- #include <stdio.h>
- #define my_int(n) printf(#n" = %d\n", n)
- typedef struct {
- int a;
- char b;
- char c;
- }struct_t1;
- typedef struct {
- char b;
- int a;
- char c;
- }struct_t2;
- int main()
- {
- my_int(sizeof(struct_t1));
- return 0;
- }
阅读(1507) | 评论(0) | 转发(1) |