C++基础:C语言中##的用法

  C语言中##称为连接符,其功能是在带参数的宏定义中将两个子串(token)联接起来,从而形成一个新的子串。

  要注意下面的用法:

  1、

  [cpp]

  #include <stdio.h>

  #define debug(format, args...) fprintf(stderr, format, args)

  void main(void){

  debug("Test \n");

  return;

  }

  有的说这种情况下字符串后面会多一个逗号,但是我用gcc编译不通过;

  2、

  [cpp]

  #include <stdio.h>

  #define debug(format, args...) fprintf(stderr, format, ##args)

  //#define debug(format, args...) fprintf(stderr, format, args)

  void main(void){

  debug("Test \n");

  return;

  }

  这样可以编译通过,执行正确;

  3、

  [cpp]

  #include <stdio.h>

  //#define debug(format, args...) fprintf(stderr, format, ##args)

  #define debug(format, args...) fprintf(stderr, format, args)

  void main(void){

  debug("Test%d \n",1);

  return;

  }

  这样也正确;

    }, tim );

  EventKey ke=new EventKey();

  Thread1 demo1=new Thread1(ke) ;

  Thread2 demo2=new Thread2(ke) ;

  demo1.start();

  demo2.start();

  }

  }

  class Thread1 extends Thread{

  private EventKey ek;

  private int ko;

  public Thread1(EventKey e){

  ek=e;

  }

  public void run(){

  synchronized(this){

  while(true){

  ko=ek.next();

  System.out.println(Thread.currentThread()+"ko:"+ko);

  if(ko % 2 !=0 ){

  System.out.println("输出的是奇数");

  System.exit(0);

  }

  }}}

  }

  class Thread2 extends Thread{

  private EventKey ek;

  private int ko;

  public Thread2(EventKey e){

  ek=e;

  }

转载于:https://www.cnblogs.com/52bokeyuan1314/p/3334767.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值