News for hackers. Stuff that matters.
Re:Tell HN: C Experts Panel – Ask us anything about C by Tronic2 on Tuesday April 14, 2020 @10:18AM (#22866270)
char effectively behaves as a signed type, making it unsuitable for binary operations (e.g. UTF-8 manipulation). I/O functions deal with char pointers, so using unsigned type like uint8_t requires casting back and forth. Is there any way out of this problem, and am I already breaking the aliasing rules with that cast?
Re:Tell HN: C Experts Panel – Ask us anything about C by _kst_ on Tuesday April 14, 2020 @07:20PM (#22872643)
Plain char is either signed (same representation as signed char) or unsigned (same representation as unsigned char), depending on the implementation.

Yes, there are real-world implementations where plain char is unsigned.

Re:Tell HN: C Experts Panel – Ask us anything about C by msebor on Tuesday April 14, 2020 @11:15AM (#22866996)
Casting between the three character types is safe and doesn't violate aliasing rules. In addition, objects of all types can be accessed by lvalues of any of the three character types (though unsigned char is recommended), so there's no problem there either.

I/O functions that take a plain char* are designed to interoperate with char arrays and strings, so passing in unsigned or signed char is a sign that they aren't being used as intended. (Functions that traffic in binary data like fread/fwrite should take void*).

Re:Tell HN: C Experts Panel – Ask us anything about C by emilfihlman on Tuesday April 14, 2020 @11:12AM (#22866955)
There are no aliasing differences between uint8_t and char as far as I know.
Re:Tell HN: C Experts Panel – Ask us anything about C by hsivonen on Tuesday April 14, 2020 @11:39AM (#22867297)
In practice not. In theory, it’s implementation-defined whether yhere are differences.
Re:Tell HN: C Experts Panel – Ask us anything about C by emilfihlman on Tuesday April 14, 2020 @11:52AM (#22867470)
At least from what I've heard that's because stdint values are optional.

6.2.5p17 The three types char, signed char, and unsigned char are collectively called the character types. The implementation shall define char to have the same range, representation, and behavior as either signed char or unsigned char. 48)

and

5.2.4.2.1 says that width of char, signed char and unsigned char are the same (8).

Re:Tell HN: C Experts Panel – Ask us anything about C by radford-neal on Tuesday April 14, 2020 @03:10PM (#22870154)
I don't think it's anything to do with uint8_t being optional. It's because a char might have more than 8 bits.
Re:Tell HN: C Experts Panel – Ask us anything about C by flatfinger on Thursday April 16, 2020 @05:08PM (#22893577)
A conforming implementation could extend the language with an 8-bit type __nonaliasingbyte which has no special aliasing privileges, and define uint8_t as being synonymous with that type.

On the other hand, the Standard should never have given character types special aliasing rules to begin with. Such rules would have been unnecessary if the Standard had noted that an access to an lvalue which is freshly visibly derived from another is an access to the lvalue from which it is derived. The question of whether a compiler recognizes a particular lvalue as "freshly visibly derived" from another is a Quality of Implementation issue outside the Standard's jurisdiction.