3 ms·
Also, char is a distinct type from both signed char and unsigned char (even though it has the same size as both and the same signedness as one of them).
by MauranKilom 4y ago
Also, char is a distinct type from both signed char and unsigned char (even though it has the same size as both and the same signedness as one of them).
- jhgb 4y agoIs signed char and unsigned char subject to the same "can alias anything" rule? I never bothered to think about this in the past. Now I'm not sure. I've known that the three types are distinct, but that just means that that the rule doesn't have to apply to all of them, not that it doesn't.
- saagarjha 4y agoYes, the rule applies to all three character types.
- jhgb 4y agoThanks. This seems mildly ungoogleable, or at least I haven't been able to find a good search result for this. So I'll keep in mind that these are three distinct types with the same aliasing behavior.
- saagarjha 4y agoActually, I take that back and should clarify: it's all three only in C. In C++ it is just char and unsigned char. (If you want to search for this, "signed char aliasing" gave me good results.)
- quibono 4y agoIs there any difference in using char vs unsigned char then? I understand these two types are different as far as the compiler's concerned. Would they behave differently too?
- MauranKilom 4y agosignedness of char is up to the implementation. You should not rely on char behaving like unsigned char.