inttypes.h

次のマクロは、inttypes.h 内で定義されています。それぞれ、変換指定子を含む文字ストリング・リテラルに展開されます。この変換指定子は、対応する整数型を変換する際に定様式入出力関数の format 引数の中で使用できる長さ修飾子によって修飾できます。 これらのマクロは、一般形式の PRI (fprintf() および fwprintf() ファミリーの関数の文字ストリング・リテラル) または SCN (fscanf() および fwscanf() ファミリーの関数の文字ストリング・リテラル) を使用し、その後に変換指定子と、<inttypes.h> 内の同様な型名に対応する名前を続けて指定します。 これらの名前の中で、接尾部の数値は型の幅を表します。例えば、PRIdFAST32 は、int_fast32_t 型の整数値を印刷するための書式制御ストリングの中で使用できます。

このヘッダーは、imaxdiv_t 型を定義します。
注: long long が使用可能であることが必要です。
imaxdiv_t は、imaxdiv() 関数から戻される値の型である構造化型です。機能上は lldiv_t と同等です。

コンパイル要件:

次に示すリストの中で、接尾部 MAX または 64 を含むすべてのマクロを使用するには、long long が使用可能であることが必要です。

#define _ISOC99_SOURCE
#include <inttypes.h>      
#include <stdio.h> 
int main(void)                                             
{                                                          

int8_t i =  40; 
printf("Demonstrating the use of the following macros:¥n");
printf("Using PRId8, the printed value of 40 "                  
"is  %" PRId8"¥n", i);
printf("Using PRIiFAST8, the printed value of 40 "               
"is  %" PRIiFAST8"¥;n", i);
printf("Using PRIoLEAST8, the printed value of 40 "              
"is  %" PRIoLEAST8 "¥n", i);
return 0;                                                  
}                          


出力:

Demonstrating the use of the following macros:  
Using PRId8, the printed value of 40 is  40     
Using PRIiFAST8, the printed value of 40 is  40 
Using PRIoLEAST8, the printed value of 40 is  50

コンパイル要件:

次に示すリストの中で、接尾部 MAX または 64 を含むすべてのマクロを使用するには、long long が使用可能であることが必要です。

符号なし整数に対する fprintf ファミリー用のマクロ:

#define _ISOC99_SOURCE
#include <inttypes.h>      
#include <stdio.h> 

int main(void)                                             
{                                                          
uint32_t i =  24000;                                       
printf("Demonstrating the use of the following macros:¥n");
printf("Using PRIuPTR, the address of the variable "           
"is  %" PRIuPTR "¥n", i);
printf("Using PRIXFAST32, the printed value of 24000 "     
"is  %" PRIXFAST32"¥n", i);
printf("Using PRIxLEAST32, the printed value of 24000 "    
"is  %" PRIxLEAST32 "¥n", i);
return 0;                                                  
}                                                         
                     
                                      

出力:

Demonstrating the use of the following macros:        
Using PRIuPTR, the address of the variable is  538874544  
Using PRIXFAST32, the printed value of 24000 is  5DC0 
Using PRIxLEAST32, the printed value of 24000 is  5dc0

コンパイル要件:

次に示すリストの中で、接尾部 MAX または 64 を含むすべてのマクロを使用するには、long long が使用可能であることが必要です。

符号付き整数に対する fscanf ファミリー用のマクロ:

#define _ISOC99_SOURCE
#include <inttypes.h>      
#include <stdio.h> 

int main(void)
{
    int32_t i;
    printf("Enter decimal value ");
    scanf("%" SCNdFAST32, i);
    printf("Print result: %" PRIdFAST32 "¥n", i);
   return 0;
}

出力:

Enter decimal value 23
Print result: 23

コンパイル要件:

次に示すリストの中で、接尾部 MAX または 64 を含むすべてのマクロを使用するには、long long が使用可能であることが必要です。

符号付き整数に対する fscanf ファミリー用のマクロ:

#define _ISOC99_SOURCE
#include <inttypes.h>      
#include <stdio.h> 

int main(void)                                   
{                                                
    intmax_t i;                                  
    printf("Enter hex value ");                  
    scanf("%" SCNxMAX, i);                      
    printf("Print result: %020" PRIxMAX "¥n", i);
    return 0;                                    
}                                                

出力:

Enter hex value 0x32              
Print result: 00000000000000000032