Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to cast an unsigned char* to char*, and treat the dereferenced pointer as if it really points to a char?

Tags:

People also ask

Should char be signed or unsigned?

On x86 systems char is generally signed. On arm systems it is generally unsigned (Apple iOS is an exception).

What is the purpose of unsigned char?

The rest part of the ASCII is known as extended ASCII. Using char or signed char we cannot store the extended ASCII values. By using the unsigned char, we can store the extended part as its range is 0 to 255.

What is the difference between char and unsigned char?

A signed char is a signed value which is typically smaller than, and is guaranteed not to be bigger than, a short . An unsigned char is an unsigned value which is typically smaller than, and is guaranteed not to be bigger than, a short .

How do you write an unsigned char?

unsigned char ch = 'a'; Initializing an unsigned char: Here we try to insert a char in the unsigned char variable with the help of ASCII value. So the ASCII value 97 will be converted to a character value, i.e. 'a' and it will be inserted in unsigned char.


Following the question titled Warning generated due wrong strcmp parameter handling, there seems to be some questions regarding what the Standard actually guarantees regarding value representation of character types.


THE QUESTION

This looks fine, but does the Standard guarantee that the (1) will always yield true?

char unsigned * p1 = ...; char          * p2 = reinterpret_cast<char *> (p1);  *p1 == *p2; // (1)