char the default type signed or not? And int ?(signed char *) to (char *) ? And the same for int ?unsigned char ?int ? And the minimum?long type is definitely bigger than char , isn't it?char - not regulated, int - signed.int , legal, but not for char .signed and unsignedchar , are signed by default.char situation is more complicated. The standard establishes three different types: char , signed char , unsigned char . In particular, a type pointer (signed char *) cannot be implicitly cast to a type (char *) .char equivalent to either signed char , or unsigned char — the choice of compiler (the standard does not require anything specific).char in the comments .unsigned charunsigned char type is an abstraction of a machine byte. The importance of this type is manifested in the fact that C can address memory only to within a byte. On most architectures, the byte size is 8 bits, but there are exceptions. For example, processors with a 36-bit architecture typically have a 9-bit byte, and in some Texas Instruments DSPs, the bytes are 16 or 32 bits. Ancient architectures can have short bytes of 4, 5, or 7 bits.CHAR_BIT 2) ) for this platform is recorded in the header file limits.h .char , short , int , etc.) do not have a strictly defined size, but depend on the platform. However, these types would not be portable ifsigned char: -127 ... 127 (not -128 ... 127; similarly, other types)unsigned char : 0 ... 255 (= 2 8 −1)signed short : -32767 ... 32767unsigned short : 0 ... 65535 (= 2 16 −1)signed int : -32767 ... 32767unsigned int : 0 ... 65535 (= 2 16 −1)signed long : -2147483647 ... 2147483647unsigned long : 0 ... 4294967295 (= 2 32 −1)signed long long : -9223372036854775807 ... 9223372036854775807unsigned long long : 0 ... 18446744073709551615 (= 2 64 −1)unsigned char value is 2 CHAR_BIT −1 (see previous paragraph).sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long) . Thus, situations like sizeof(char)=sizeof(long)=32 are legitimate. For some DSPs from Texas Instruments, it is.limits.h header file.long long type, there are more integer types and confusion. To restore order, the standard entered the header file stdint.h , where types like int16_t (equal to 16 bits) are int_least16_t , int_least16_t (the minimum type capable of holding 16 bits), int_fast16_t (at least 16 bits, working with this type is the fastest on this platform), etc.int , short , long and other types discussed above. In addition, they give the programmer a choice between speed and size.int16_t , with a strict indication of size, portability suffers: for example, a 16-bit register may simply not be found on an architecture with a 9-bit byte. Therefore, the standard here clearly says that these types are optional. But considering that no matter what code you write, a little less than in all cases, the target architecture is fixed even in the worst case to the nearest family (say, x86 or AVR), within which the size of a byte cannot suddenly change, the portability actually remains . Moreover, types like int16_t turned out to be even more popular than int_least16_t and int_fast16_t , and with low-level programming (microcontrollers, device drivers), and even more so, because there is often uncertainty about the size of a variable is simply impermissible.UCHAR_BIT correct to call this macro UCHAR_BIT , but for reasons of compatibility it is called as it is called.Source: https://habr.com/ru/post/156593/
All Articles