我在使用 sscanf 时遇到了奇怪的行为。根据结构中 a 和 b 的顺序,其中一个是 0。
typedef struct MyStructure{
uint8_t a;
uint8_t b;
}MyStructure;
这是让我感到困惑的代码:
if (2 == sscanf(rawCommand,"%*s %*s %"SCNu8" %"SCNu8"", &a, &b)){
... some code
}
当我将结构体中的变量顺序更改为:
typedef struct MyStructure{
uint8_t b;
uint8_t a;
}MyStructure;
sscanf 返回 2 但 a 为 0;
我已经在 linux 上的 32 位 GCC 上对其进行了测试,上面的代码可以两种方式工作。但是在 Windows 7 上使用 64 位 GCC 编译时,它的行为就像我提到的那样。在这两个系统上,我都使用 GCC 4.8.1。