#include <stdio.h>
#include <inttypes.h>
int main(void)
{
int8_t int8;
int16_t int16;
int32_t int32;
int64_t int64;
uint8_t uint8;
uint16_t uint16;
uint32_t uint32;
uint64_t uint64;
scanf("%"SCNd8"%"SCNd16"%"SCNd32"%"SCNd64"%"SCNu8"%"SCNu16"%"SCNu32"%"SCNu64,
&int8, &int16, &int32, &int64, &uint8, &uint16, &uint32, &uint64);
printf("%"PRId8"\n%"PRId16"\n%"PRId32"\n%"PRId64"\n%"PRIu8"\n%"PRIu16"\n%"PRIu32"\n%"PRIu64"\n",
int8, int16, int32, int64, uint8, uint16, uint32, uint64);
return 0;
}
I can’t compile this code using latest gcc + MinGW + Netbeans + Windows. Netbeans says “unable to resolve identifier SCNd8 and SCNu8”. I can’t find any reference for SCNd8 and SCNu8 on gcc man page although http://linux.die.net/include/inttypes.h defines them. I don’t receive syntax error for using PRId8 or PRIu8.
MinGW inttypes.h (lacks SCNd8 and SCNu8 ) (sample code)
#define PRIXFAST64 "I64X"
#define PRIXMAX "I64X"
#define PRIXPTR "X"
/*
* fscanf macros for signed int types
* NOTE: if 32-bit int is used for int_fast8_t and int_fast16_t
* (see stdint.h, 7.18.1.3), FAST8 and FAST16 should have
* no length identifiers
*/
#define SCNd16 "hd"
#define SCNd32 "d"
#define SCNd64 "I64d"
#define SCNdLEAST16 "hd"
#define SCNdLEAST32 "d"
#define SCNdLEAST64 "I64d"
#define SCNdFAST16 "hd"
You could add the following after
#include <inttypes.h>:Which should be appropriate for most platforms.
Clarification:
Where “most platforms” refers to platforms with a C99-compliant
fscanf/scanfthat can handle thehhprefix forchar, not just thehprefix forshort.