gcc(windows + MinGW)是否在inttypes.h中定义了SCNd8,SCNu8? [英] Does gcc(windows + MinGW) defines SCNd8, SCNu8 in inttypes.h?

查看:669
本文介绍了gcc(windows + MinGW)是否在inttypes.h中定义了SCNd8,SCNu8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  #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\\\
%PRId16\\\
%PRId32\\\
%PRId64\\\
%PRIu8\\\
%PRIu16 \ n%PRIu32\\\
%PRIu64\ n,
int8,int16,int32,int64,uint8,uint16,uint32,uint64);

返回0;
}

我无法使用最新的gcc + MinGW + Netbeans + Windows编译此代码。 Netbeans说无法解析标识符SCNd8和SCNu8。虽然 http://linux.die我在gcc手册页上找不到SCNd8和SCNu8的任何参考.net / include / inttypes.h 定义它们。我没有收到使用PRId8或PRIu8的语法错误。

MinGW inttypes.h(缺少SCNd8和SCNu8)(示例代码)

  #define PRIXFAST64I64X

#define PRIXMAXI64X
#define PRIXPTRX
$ b $ * / $
* fscanf宏对于带符号的int类型
*注意:如果32位int用于int_fast8_t和int_fast16_t
*(参见stdint.h,7.18.1.3),则FAST8和FAST16应该有
* no长度标识符
* /

#define SCNd16hd
#define SCNd32d
#define SCNd64I64d

#定义SCNdLEAST16hd
#define SCNdLEAST32d
#define SCNdLEAST64I64d

#define SCNdFAST16hd


解决方案

您可以在 #include< inttypes.h> code $:b
$ b

  #ifndef SCNd8 
#define SCNd8hhd
#endif
#ifndef SCNu8
#define SCNu8hhu
#endif

哪个应该适合大多数platfo rc。

澄清:
其中大多数平台是指符合C99的平台 fscanf / scanf 可以处理 char hh 前缀,不只是 h 前缀


#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>:

#ifndef SCNd8
  #define SCNd8 "hhd"
#endif
#ifndef SCNu8
  #define SCNu8 "hhu"
#endif

Which should be appropriate for most platforms.

Clarification: Where "most platforms" refers to platforms with a C99-compliant fscanf/scanf that can handle the hh prefix for char, not just the h prefix for short.

这篇关于gcc(windows + MinGW)是否在inttypes.h中定义了SCNd8,SCNu8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆