抑制“ISO C99要求使用休息参数”。

考虑以下两个宏:
#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.rn" ) ; 
    } 
    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.rn" ) ; 
    } 
  } 
}

#define PERROR_LOCKFREE( v, s, ... ) { 
  if( VERBOSITY_CHECK( v ) ) { 
    PERRNO ;
    fprintf( stderr, s, ## __VA_ARGS__ ) ; 
    fflush( stderr ) ; 
  } 
}
现在考虑使用这些示例:
PNORM( verbose, "tSomeText [%d] More [%p]rn", 0, ptr ) ;
使用-pedantic选项和-std = c99编译时,我多次出现此错误:
mycode.c:410:112: warning: ISO C99 requires rest arguments to be used
编者对此抱怨是对的,但有一种简单的方法可以抑制这个警告,因为我不关心它吗?     
已邀请:
s
参数与可变参数组合使用,以便始终至少有一个参数作为省略号的一部分。这也允许您避免使用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.rn" ) ; 
    } 
    fprintf( stdout, __VA_ARGS__ ) ; 
    fflush( stdout ) ; 
    if( ( errno = pthread_mutex_unlock(&server.output_mutex) ) ) { 
      PERROR_LOCKFREE( normal, "tpthread_mutex_unlock failed on output_mutex.rn" ) ; 
    } 
  } 
}

#define PERROR_LOCKFREE( v, ... ) { 
  if( VERBOSITY_CHECK( v ) ) { 
    PERRNO ;
    fprintf( stderr, __VA_ARGS__ ) ; 
    fflush( stderr ) ; 
  } 
}
    
##
标记与
__VA_ARGS__
结合使用是gcc扩展,不属于ISO C99。这就是你收到警告的原因。     
您可以在宏周围禁用警告,或在GCC中使用
pragma Warnings
完全禁用特定警告。你也可以不使用
-pedantic
,因为它很好,很迂腐。     
取决于什么对你来说很简单。在P99中有P99条件允许你做类似的事情
#define USER_MACRO(...) P99_IF_DEC_LE(P99_NARG(__VA_ARGS__),2)(USER_MACRO2(__VA_ARGS__))(USER_MACRO3(__VA_ARGS__))
因此,没有必要扩展gcc的
,##
。     

要回复问题请先登录注册