News for hackers. Stuff that matters.
Re:Implementing Hash Tables in C by matheusmoreira on Saturday October 16, 2021 @04:19PM (#28891114)
> uint8_t is not guaranteed to be unsigned char but in practice almost always is.

Does this imply any unsigned char typedef is able to alias anything? Or is uint8_t a compiler special case?

Re:Implementing Hash Tables in C by simias on Saturday October 16, 2021 @04:25PM (#28891164)
`char` is not guaranteed to be 8 bits and in some more exotic environments (DSPs for instance) may not be.

IIRC POSIX guarantees that char is 8 bits though (but I still think that the sign is implementation-dependent).

But as I said in a parent comment, I don't understand why it's even relevant. If you want to alias any type then use `char *` and not anything else. I don't understand why one would prefer using stdint for that.

Re:Implementing Hash Tables in C by matheusmoreira on Saturday October 16, 2021 @04:51PM (#28891388)
Because sometimes people need to reinterpret data as an array of 8/16/32/64 bit elements. Sometimes people also need to reinterpret things as a structure.

This is independent of how many bytes the underlying platform can address. If we have 8 bit processing code but the platform can only address 16 bits at a time, it should be up to the compiler to generate code that works. Compilers already do stuff like that in other circumstances.

Re:Implementing Hash Tables in C by jeffbee on Saturday October 16, 2021 @05:18PM (#28891635)
Those people need to be copying, otherwise the reinterpretation might not be working. The char data might not be correctly aligned, for example. Recently went through a big nightmare where a C++ codebase that had accreted on x86 was thought to be ported to another platform where alignment actually matters and there were all manner of rare low-level malfunctions stemming from the idea that you can just wantonly cast a char* to structured data.
Re:Implementing Hash Tables in C by jcranmer on Saturday October 16, 2021 @06:45PM (#28892257)
The strict aliasing rules look through typedefs (and const/volatile-qualifiers). It's possible to use char, signed char, and unsigned char, or any typedef thereof, or any typedef of any typedef, etc., to access any memory whatsoever.