C 具有 uint8 数组奇怪行为的结构
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
,我们可以在 coliru 上看到uint8_t
是这种情况。cstdint
标头包含 stdint.h
并且确实有一个 typedef uint8_t
unsigned char
:
typedef unsigned char uint8_t;
您看到的输出与将a.CH[2]
视为char
类型的cout
一致,
相关文章:
- 如何使用boost::具有嵌套结构和最小代码更改的序列化
- 具有结构成员char数组的sscanf
- 具有引用成员的结构是否具有唯一的对象表示形式
- 使用 std::index_sequence 初始化具有固定大小数组成员的 POD 结构容器
- 使用具有结构不完整类型错误的模板
- 正在复制具有未初始化成员的结构
- C++ 中具有 O(1) 搜索时间复杂度的数据结构
- 结构体和类的不同大小(),彼此具有相同的字段类型
- 为什么"具有常量成员的结构"类型的指针不能指向"具有非常量成员的结构"?
- C++-将具有引用的长参数列表重构为结构
- C++具有动态分配的字符数组的结构
- 在C 中,是否有树木数据结构具有相似的功能
- C 结构具有CHAR数组以不寻常的方式初始化为零
- 自定义链表创建 RtlValidateHeap 错误,其结构具有链表
- 如果所述结构具有构造函数,则带有 new[] 的结构数组似乎不起作用
- 结构具有构造的向量
- 当结构具有默认构造函数时,为什么我的C++程序在发布模式下崩溃
- 允许嵌套结构具有包含类的实例
- 库,这有助于包装结构具有良好的性能
- Boost Fusion结构具有逗号上的多参数模板类型阻塞