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?

5
  • uint8_t is probably typedef'ed as a char ... I am guessing that is what uint8 really is. Commented Apr 29, 2015 at 17:05
  • 2
    Also since I see cout I am guessing this should really be tagged C++ Commented Apr 29, 2015 at 17:06
  • You are right Shafik Yaghmour Commented Apr 29, 2015 at 17:15
  • This works AnchorPixel a; a.CH[2] = 5; cout << (int32)a.CH[2]; Commented Apr 29, 2015 at 17:15
  • Which comment and I right about? About tagging this C++ or about the typedef? Commented Apr 29, 2015 at 17:15

1 Answer 1

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,

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.