LoginSignup
36
38

More than 3 years have passed since last update.

[C言語] printf系の関数に指定するフォーマット引数

Last updated at Posted at 2015-11-23

数値をprintfで表示させようとした時に、こんなワーニングでコンパイラに怒られてしまうことがよくあるので、メモとして残しました。

warningの例(gcc)
movie_info.c:38:10: 警告: 書式 ‘%u’ は引数の型が ‘unsigned int’ であると予期されますが、第 2 引 数の型は ‘int64_t {aka long int}’ です [-Wformat=]
   printf("  <bitrate>%ud</bitrate>\n", vst->codec->bit_rate);
          ^
movie_info.c: 関数 ‘print_audio_tag’ 内:
movie_info.c:73:10: 警告: 書式 ‘%ld’ は引数の型が ‘long int’ であると予期されますが、第 2 引数の型は ‘int’ です [-Wformat=]
   printf("  <sample_rate>%ld</sample_rate>\n", ast->codec->sample_rate);

一覧

フォーマット
ssize_t %zd
size_t %zu
intmax_t %jd
uintmax_t %ju
signed char %hhd
unsigned char %hhu
short int %hd
unsigned short int %hu
int %d
unsigned int %u
long int %ld
unsigned long int %lu
long long int %lld
unsigned long long int %llu
36
38
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
36
38