4 ms·
Thanks. I misremembered C's rules as only unsigned char having this special property (as well as plain char if it's unsigned), but not signed char.
by tom_mellior 7y ago
Thanks. I misremembered C's rules as only unsigned char having this special property (as well as plain char if it's unsigned), but not signed char.
- BeeOnRope 7y agoI think you are partly right. My understanding is that the special aliasing rules apply only to `char` and `unsigned char` in C++, not to `signed char`. In C, however, I think it applies to all three. AFAIK char is a distinct type from signed char and unsigned char, regardless of whether it is signed or not. In practice it will have the same representation as those but will not be the same type: https://godbolt.org/z/D6ylkf https://godbolt.org/z/D6ylkf So `signed char` would seem to be a way to get a strongly typed char not subject to the aliasing rules (even if bare char is signed), but compilers don't take advantage as far as I can tell.
- slavik81 7y agoJust to back you up, this post quotes both standards: https://stackoverflow.com/a/51228315/331041 https://stackoverflow.com/a/51228315/331041