In the C++ standard:
sizeof(char),sizeof(signed char)andsizeof(unsigned char)are1.
Are there any other types in C++ which have a fixed sizeof?
Does the empty structure correspond to this definition?
No. As you say, sizeof(signed char), sizeof(unsigned char), and sizeof(char) are defined by the standard to be 1. Note that char must be either signed or unsigned but it is always considered to be a distinct type. The sizeof anything else is down to the implementation subject to some constraints (e.g. sizeof(long) cannot be less than sizeof(int).)
The C++ standard requires sizeof an empty class to be an integral value greater than zero (otherwise pointer arithmetic would break horribly).
1) Are there any other types in C++ which have a fixed sizeof?
There are arrays which have specified size:
sizeof(T[N]) == N * sizeof(T)
so sizeof(char[42]) is 42.
2) Does the empty structure correspond to this definition?
Empty struct is neither char, signed char or unsigned char, so it doesn't correspond to this definition. (BTW its sizeof cannot be 0).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With