This question originally springs from the fact that I'm currently working with OpenGL bindings from Rust.
Example signature of an OpenGL function which returns an unsigned char pointer:
const GLubyte* glGetString(GLenum name);
However, some functions in Rust which converts C strings to safe abstractions requires pointers of type const i8* (so, equivalent to signed chars in C).
Now, my question is, does conversion between signed and unsigned char pointers make me potentially lose information about the string characters?
I know that both signed and unsigned characters have the same size, and I realize that converting between signed and unsigned types such as char changes the way that numbers are interpreted, but what I'm not sure about is whether this number interpretation actually matters for strings at the lower level, when printing them to the screen or saving them to files.
CodePudding user response:
A conversion between pointer type never make you loses information because a pointer is just an address no matter in which type you store it.
A type of a pointer is just an information about how you would treat the pointed data.
For your issue, if you use only ASCII with 7 bits characters (for short, only the english characters) you will not loose any information by passing an unsigned to a signed char or a signed one to an unsigned. Because char type use generally 8 bits and the signed bits is the one not use by ASCII 7 bits.
A signed char or an unsigned char will have the same value as long as you stick with ASCII 7 bits.
CodePudding user response:
Same as Stiven, except it doesn't matter even if it's UTF-8 8-bit characters. signed vs unsigned only produces different results when you do arithmetic operations on the items, and that should never happen for a string characters.