zoukankan      html  css  js  c++  java
  • Linux C 中连接操作符##

    #include <stdio.h>
    #define test(x) test ## x
    #define DPRINT( fmt, args...) \
    { 	\
    	printf("File : %s Funtion : %s Line : %d  \t", __FILE__, __FUNCTION__, __LINE__ );\
    	printf( fmt, ##args );\
    }
    
    void test1(int a)
    {
    	DPRINT("Integer : %d \n", a);
    }
    
    void test2(char *s)
    {
    	DPRINT("String : %s \n", s);
    }
    
    int main(void)
    {
    	test(1)(100);
    	test(2)("hello");
    	return 0;
    }
    

    打印信息:

    ***************************************************

     File : test.c Funtion : test1 Line : 11         Integer : 100
     File : test.c Funtion : test2 Line : 16         String : hello

    ***************************************************

    #define DPRINT( fmt, args...) \
    { \
    printf("File : %s Funtion : %s Line : %d  \t", __FILE__, __FUNCTION__, __LINE__ );\
    printf( fmt, ##args );\
    }

    这样定义宏有个问题, 标准printf()函数有返回值, 只是我们很少用

    另外一种定义:

    #define DPRINT( fmt, args...)     \
      printf("File : %s Funtion : %s Line : %d  \t"fmt, __FILE__, __FUNCTION__, __LINE__ ,##args )

    fmt不能为指针

    *****************************************

    const  char *s= "string";

    printf(s);

    *****************************************

    是合法的,可以打印出string

    但DPRINT(s)就不合法

  • 相关阅读:
    学习canvas过程中的小菜鸟
    小菜鸟谈html语义化
    mui常用方法
    mui的侧滑菜单如何禁用手势侧滑
    ajax 传递数组参数
    LNMP状态管理命令
    LNMP相关软件目录及文件位置
    ubuntu常用命令
    Ubuntu设置允许root用户登录
    linux一键安装web环境(sh-1.3.0)
  • 原文地址:https://www.cnblogs.com/Neddy/p/2335399.html
Copyright © 2011-2022 走看看