0

I have problem with following C struct:

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

Actually, I have problem with CH array inside it. I just cannot manipulate CH array. For example, following program

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

gives output:

If I change CH type from uint8 to int32, problem disappears. This works:

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

Any ideas?

Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
Bogdan
  • 33
  • 1
  • 5

1 Answers1

1

It seems likely that uint8 is typedef'ed as a unsigned char, we can see on coliru for uint8_t this is the case. The cstdint header includes stdint.h and there uint8_t is indeed a typedef to unsigned char:

typedef unsigned char       uint8_t;

The output you are seeing is consistent with cout treating a.CH[2] as a char type,

Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740