有没有办法将char []转换为unsigned char *?
char buf[50] = "this is a test"; unsigned char* conbuf = // what should I add here
解决方法
虽然它在技术上可能不是100%合法,但这将起作用reinterpret_cast< unsigned char *>(buf).
这不是100%技术合法的原因是由于5.2.10 expr.reinterpret.cast bullet 7.
A pointer to an object can be explicitly converted to a pointer to an object of a different type. original type yields the original pointer value,the result of such a pointer conversion is unspecified.
我认为* reinterpret_cast< unsigned char *>(buf)=’a’未指定,但* reinterpret_cast< char *>(reinterpret_cast< unsigned char *>(buf))=’a’是正常的.