In C, does sizeof measure its result in octet bytes or characters?

Although it charconsists of 1 bytefor all the compilers I know, I have the impression that it Cdoes not guarantee the length char, it only guarantees that char < short < long. Therefore, I suggested that it sizeofmeasures its result in charto abstract from the platform on which it works. To make it more general, I thought it was size_tdefined in terms char.

But now, as far as I can see google search, it seems to sizeofreturn the result in bytes.

Was I completely mistaken in my assumption or is there anything more than that?

+4
source share
3 answers

char - data type C, which is a byte; they are conceptually the same.

If you ask if the result is always in an octet (8-bit values), the answer is no ; it is in bytes ( chars), and if the byte has a different number of bits, then the result will be in terms of multiples of this set of bits.

+4
source

The unit used sizeofis char. One of the axioms of the language is that sizeof(char) == 1.

Therefore, for systems with charmore than 8 bits, sizeofit is not measured in 8-bit units.

+10
source

sizeof - .

C char, , 8 .

, a char, CHAR_BIT <limits.h>

+7

Source: https://habr.com/ru/post/1529476/


All Articles