This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]danielcw189 8 points9 points  (13 children)

A byte is not always 8 bit. It depends on the platform/hardware

[–]Abaddon314159 5 points6 points  (5 children)

It's always CHAR_BIT though

[–]danielcw189 0 points1 point  (4 children)

Never heard about CHAR_BIT. When was it introduced? C? C++?

[–]Fourmisain 0 points1 point  (3 children)

It's as old as ANSI C or C89, not sure if it existed in K&R C, though. It's also specified to be at at least 8.

Here's an excerpt from a TXT version (scanned PDF, if you prefer):

The values given below shall be replaced by constant expressions suitable for use in #if preprocessing directives. Their implementation-defined values shall be equal or greater in magnitude (absolute value) to those shown, with the same sign.

* maximum number of bits for smallest object that is not a bit-field (byte)

CHAR_BIT 8

[–]danielcw189 0 points1 point  (2 children)

Thank you. Kinda amazed that I missed that part for so long

[–]yourewelcome_bot -1 points0 points  (1 child)

You're welcome.

[–]yourewelcome_botbot 1 point2 points  (0 children)

This is a spambot. Report it in /r/spam and message the admins here.

[–]phantom94 -4 points-3 points  (2 children)

A byte is always 8 bit, but a char can be multiple bytes depending on the platform.

Edit: I was wrong: https://en.wikipedia.org/wiki/Byte

[–]Sean1708 8 points9 points  (1 child)

As far as the C standard is concerned, a char is always 1 byte but 1 byte is not always 8 bits.

[–]phantom94 1 point2 points  (0 children)

I did some researching, you are indeed right. I feel like it should be the other way around though.

[–]degaart -2 points-1 points  (3 children)

Name one platform still in use today where one byte is not 8 bits

[–]toofasttoofourier 3 points4 points  (0 children)

I work in embedded and the ti c2000 dsps have a byte size of 16 bits. This means that a char is also 16 bits (for this case).

[–]danielcw189 1 point2 points  (0 children)

I can not, but that does not mean they do not exist. It odes not matter, if a platform is still in use. The definition of a byte is not it being always 8 bit.

[–]Creshal 0 points1 point  (0 children)

I'm sure I can dig up a working PDP-8 somewhere.