抑制“ISO C99需要使用休息参数” [英] Suppressing "ISO C99 requires rest arguments to be used"

查看:485
本文介绍了抑制“ISO C99需要使用休息参数”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下两个宏:

  #define PNORM(v,s,...){\ $ b $(b)if(VERBOSITY_CHECK(v)){\ 
if((errno = pthread_mutex_lock(& server.output_mutex))){\
PERROR_LOCKFREE(正常,\ tpthread_mutex_lock在output_mutex上失败。 \r\\\
); \
} \
fprintf(stdout,s,## __VA_ARGS__); \
fflush(stdout); \
if((errno = pthread_mutex_unlock(& server.output_mutex))){\
PERROR_LOCKFREE(normal,\ tpthread_mutex_unlock failed_output_mutex.\r\\\
); \
} \
} \
}

#define PERROR_LOCKFREE(v,s,...){\
if( VERBOSITY_CHECK(v)){\
PERRNO; \
fprintf(stderr,s,## __VA_ARGS__); \
fflush(stderr); \
} \
}

现在考虑使用这些示例:

  PNORM(verbose,\ tSomeText [%d] More [%p] \r\\\
, 0,ptr);

使用-pedantic选项和-std = c99进行编译时,我多次出现此错误:

  mycode.c:410:112:warning:ISO C99需要使用其余参数

编译器对此抱怨正确,但有没有一种简单的方法可以抑制这个警告,因为我不关心它?

解决方案>

s 参数与可变参数结合使用,一个参数作为省略号的一部分。这也可以避免使用GCC的,## 扩展:

 <$ c $ (vERBOSITY_CHECK(v)){\ 
if((errno = pthread_mutex_lock(& server.output_mutex))){\
if( \\
PERROR_LOCKFREE(正常,\ tpthread_mutex_lock在output_mutex. \ r \ n上失败); \
} \
fprintf(stdout,__VA_ARGS__); \
fflush(stdout); \
if((errno = pthread_mutex_unlock(& server.output_mutex))){\
PERROR_LOCKFREE(normal,\ tpthread_mutex_unlock failed_output_mutex.\r\\\
); \
} \
} \
}

#define PERROR_LOCKFREE(v,...){\
if(VERBOSITY_CHECK( v)){\
PERRNO; \
fprintf(stderr,__VA_ARGS__); \
fflush(stderr); \
} \
}


Consider the following two macros:

#define PNORM( v, s, ... )  { \
  if( VERBOSITY_CHECK( v ) ) { \
    if( ( errno = pthread_mutex_lock(&server.output_mutex) ) ) { \
      PERROR_LOCKFREE( normal, "\tpthread_mutex_lock failed on output_mutex.\r\n" ) ; \
    } \
    fprintf( stdout, s, ## __VA_ARGS__ ) ; \
    fflush( stdout ) ; \
    if( ( errno = pthread_mutex_unlock(&server.output_mutex) ) ) { \
      PERROR_LOCKFREE( normal, "\tpthread_mutex_unlock failed on output_mutex.\r\n" ) ; \
    } \
  } \
}

#define PERROR_LOCKFREE( v, s, ... ) { \
  if( VERBOSITY_CHECK( v ) ) { \
    PERRNO ;\
    fprintf( stderr, s, ## __VA_ARGS__ ) ; \
    fflush( stderr ) ; \
  } \
}

Now consider an example use of these:

PNORM( verbose, "\tSomeText [%d] More [%p]\r\n", 0, ptr ) ;

When compiled with the -pedantic option and -std=c99 I get this error many times:

mycode.c:410:112: warning: ISO C99 requires rest arguments to be used

The complier is right in complaining about this but is there a simple way I can suppress this warning since I don't care about it?

解决方案

Combine the s argument with the variadic arguments so that you always have at least one argument as part of the ellipsis. This also allows you to avoid using the ,## extension of GCC:

#define PNORM( v, ... )  { \
  if( VERBOSITY_CHECK( v ) ) { \
    if( ( errno = pthread_mutex_lock(&server.output_mutex) ) ) { \
      PERROR_LOCKFREE( normal, "\tpthread_mutex_lock failed on output_mutex.\r\n" ) ; \
    } \
    fprintf( stdout, __VA_ARGS__ ) ; \
    fflush( stdout ) ; \
    if( ( errno = pthread_mutex_unlock(&server.output_mutex) ) ) { \
      PERROR_LOCKFREE( normal, "\tpthread_mutex_unlock failed on output_mutex.\r\n" ) ; \
    } \
  } \
}

#define PERROR_LOCKFREE( v, ... ) { \
  if( VERBOSITY_CHECK( v ) ) { \
    PERRNO ;\
    fprintf( stderr, __VA_ARGS__ ) ; \
    fflush( stderr ) ; \
  } \
}

这篇关于抑制“ISO C99需要使用休息参数”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆