# byte is equal 8 bits???

• 10-15-2004
Micko
byte is equal 8 bits???
Hi, I've read in the Standard this:
"The sizeof operator yields the number of bytes in the object representation of its operand...
sizeof(char), sizeof(signed char), sizeof(unsigned char) are 1;..."
I remebered a post a while ago where I read that because of sizeof(char) is 1 that doesn't mena that it is 8 bits and that number of bits in the byte could be variable. Does it mean that number of bits in byte can be 6 for example?

On my machine sizeof(double) and sizeof(long double) are equal (8) but I suppose that there are different number of bits. Am I right?
Can we talk about number of bits which specific type occupies in memory, for example int is 32 bit on most machines or maybe it is corectly to say int is 4 bytes on most machines?
Thanks!
• 10-15-2004
pablo615
The number of bytes that a data type varies based on the system. It is typical that a char is 1 byte, but unicode and multibyte characters exist to support all those other languages that don't use the (roman?) alphabet, and those types are not 1 byte, but a compiler might just call them chars (are there unicode only compilers that default the char to tow bytes out there?)

A byte is always equal to 8 bits. It will be the same from machine to machine, OS to OS. Some combinations, like long double, don't really do anything meaningful, but if you said double double, then that might be 16 bytes on your system (I've not used a double double, so I don't know for certain).

Int is almost universally 32 bits, or 4 bytes. On a 64 bit platform, an int might be 64 bits, but I don't have a 64 bit system to even test that theory on...
• 10-15-2004
Dave_Sinkula
>Does it mean that number of bits in byte can be 6 for example?

No, CHAR_BIT must be at least 8.

>On my machine sizeof(double) and sizeof(long double) are equal (8) but I suppose that there are different number of bits. Am I right?

Maybe your implementation simply chooses not to deal with a long double.

>Can we talk about number of bits which specific type occupies in memory, for example int is 32 bit on most machines or maybe it is corectly to say int is 4 bytes on most machines?

I prefer to say that an int occupies exactly sizeof int bytes, each of which contains exactly CHAR_BIT bits.
• 10-15-2004
Thantos
Quote:

It is typical that a char is 1 byte
sizeof(char) is ALWAYS 1 byte

Now there are wchar variables for unicode that could be the same size or larger then char depending on exactly how big a char really is in terms of bits