invalid conversion from ‘const BYTE* {aka const unsigned char*}’ to ‘BYTE_PTR {aka unsigned char*}’

StackOverflow https://stackoverflow.com/questions/23486227

  •  16-07-2023
  •  | 
  •  

문제

I don't know why g++ compiler gives me error when compiling this code:

typedef unsigned char BYTE;
typedef BYTE* BYTE_PTR;

const BYTE myByte[] = {0x00, 0xFF};
const BYTE_PTR myByte_ptr = myByte;

compiler gives me this error:

error: invalid conversion from ‘const BYTE* {aka const unsigned char*}’ to ‘BYTE_PTR {aka unsigned char*}’ [-fpermissive]

But this code is OK

const BYTE myByte[] = {0x00, 0xFF};
const unsigned char* myByte_ptr = myByte;
도움이 되었습니까?

해결책

Duplicate of typedef pointer const weirdness

And in short: const BYTE_PTR is actually unsigned char* const, but not const unsigned char*.

That's why the compiler complains.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top