Simply put in C and variants (unlike that wuss java with its virtual machine) the size of primitive types on different targets can vary greatly, and there is really no guarantee unless you use the fixed width types defined in stdint.h
, and even then your implemenation has to support them.
Anyway hypothetically(because on most modern machines a byte is an octet, for networking purposes I assume(ASCII)) does sizeof return the size of a datatype in bytes or in octets?
Answer:
sizeof
returns the size of the type in bytes.Example:
sizeof(char)
is 100% guaranteed to be1
, but this does not mean, that it's one octet (8 bits).Proved by the standard:
in 6.5.3.4, point 2:
Also, in Section 3.6, point 3: