次の2つのマクロについて考えてみます。
#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 ) ; \
} \
}
次に、これらの使用例を考えてみましょう。
PNORM( verbose, "\tSomeText [%d] More [%p]\r\n", 0, ptr ) ;
-pedanticオプションと-std=c99を指定してコンパイルすると、このエラーが何度も発生します。
mycode.c:410:112: warning: ISO C99 requires rest arguments to be used
コンパイラーはこれについて不平を言うのは正しいですが、私はそれを気にしないので、この警告を抑制することができる簡単な方法はありますか?