Can I turn unsigned char into char and vice versa?

后端 未结 6 2106
死守一世寂寞
死守一世寂寞 2020-11-29 20:03

I want to use a function that expects data like this:

void process(char *data_in, int data_len);

So it\'s just processing some bytes really

6条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 21:08

    unsigned char or signed char is just interpretation: there is no conversion happening.

    Since you are processing bytes, to show intent, it would be better to declare as

    void process(unsigned char *data_in, int data_len);
    

    [As noted by an editor: A plain char may be either a signed or an unsigned type. The C and C++ standards explicitly allow either (it is always a separate type from either unsigned char or signed char, but has the same range as one of them)]

提交回复
热议问题