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

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -