具有 uint8 数组奇怪行为的 C 结构

C Struct with uint8 array weird behavior

我在使用以下 C 结构时遇到问题:

typedef struct AnchorPixel{
    int32 X;
    int32 Y;
    uint8 CH[5];
} AnchorPixel;

实际上,我对其中的 CH 数组有疑问。我就是无法操作 CH 数组。例如,下面的程序

AnchorPixel a;
a.CH[2] = 5;
cout << a.CH[2];

给出输出:

如果我将 CH 类型从 uint8 更改为 int32,问题就会消失。这有效:

typedef struct AnchorPixel{
        int32 X;
        int32 Y;
        int32 CH[5]; 
    } AnchorPixel;

有什么想法吗?

似乎 uint8 被类型定义为 unsigned char,我们 can see on coliru 对于 uint8_t 就是这种情况。 cstdint header 包括 stdint.h 并且 uint8_t 确实是 unsigned char:

的类型定义
typedef unsigned char       uint8_t;

您看到的输出与 couta.CH[2] 视为 char 类型一致,