c++ - Convert char array to unsigned char* -
is there way convert char[]
unsigned char*
?
char buf[50] = "this test"; unsigned char* conbuf = // should add here
although may not technically 100% legal work reinterpret_cast<unsigned char*>(buf)
.
the reason not 100% technically legal due section 5.2.10 expr.reinterpret.cast
bullet 7.
a pointer object can explicitly converted pointer object of different type. original type yields original pointer value, result of such pointer conversion unspecified.
which take mean *reinterpret_cast<unsigned char*>(buf) = 'a'
unspecified *reinterpret_cast<char*>(reinterpret_cast<unsigned char*>(buf)) = 'a'
ok.
Comments
Post a Comment