小编Cly*_* B.的帖子

尽管使用相同的固定长度数据类型,C 程序在不同的机器上产生不同的结果

我在尝试 inttypes.h 时编写的简单程序:

#include <stdio.h>
#include <stdbool.h>
#include <inttypes.h>

bool get_bit(uint32_t x, uint8_t n) {
    x >>= n;
    return x & 1;
}

int main() {
    uint32_t x;
    uint8_t n;

    printf ("Enter x: ");
    scanf("%"SCNu32, &x);

    printf ("Enter n: ");
    scanf("%"SCNu8, &n);

    printf("The %"PRIu8"th bit of %"PRIu32" is: %d", n, x, get_bit(x, n));
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

在我的手机(64 位八核 ARN LTE Soc Android 10)上,它工作正常:

Enter x: 1
Enter n: 0
The 0th bit of 1 is: 1
Run Code Online (Sandbox Code Playgroud)

但在我的计算机(64 位 x86 Windows …

c windows mingw scanf c99

37
推荐指数
1
解决办法
2412
查看次数

标签 统计

c ×1

c99 ×1

mingw ×1

scanf ×1

windows ×1