4

Quoting from C++14 ISO standard (Freely available working draft ) (Page 6, section 1.7)

The fundamental storage unit in the C++ memory model is the byte. A byte is at least large enough to contain any member of the basic execution character set (2.3) and the eight-bit code units of the Unicode UTF-8 encoding form and is composed of a contiguous sequence of bits, the number of which is implementation- defined....

The question is:

Doesn't the above imply that a byte will always contain 8 bits, since it has to contain 8-bit code units, and the basic execution character set contains all the basic english and mathematical symbols which I hope will require at least 8 bits for storage? Why then, it says that number of bits is implementation defined?

Andrew
  • 5,212
  • 1
  • 22
  • 40
Ujjwal Aryan
  • 3,827
  • 3
  • 20
  • 31
  • 11
    It says "at least...". There's nothing to stop it being larger than 8. – Andrew Jun 15 '16 at 15:20
  • 1
    "A byte is **at least** large enough to contain ...". This definition allows for 42-bits bytes. – peppe Jun 15 '16 at 15:21
  • I thought about it. But then, if it is being larger, isn't that an inefficient utilization of memory space ? Sorry but, i am unaware of these details. – Ujjwal Aryan Jun 15 '16 at 15:21
  • 4
    If your word size is 36 bits (GE 645, PDP-10), then you can have 9-bit bytes. – Mark Plotnick Jun 15 '16 at 15:27
  • The C++ memory types are based on ranges, not on bit-widths. – Thomas Matthews Jun 15 '16 at 15:27
  • Packed data can still be packed. Asking about the advantages and disadvantages of having larger bytes would be the subject of a completely new question, though. –  Jun 15 '16 at 15:28
  • @UjjwalAryan It would be inefficient on many platforms, but they're not forced to do so. But on some platforms, it might be more efficient to make them bigger, and that's why the standard doesn't force them to make them 8 bits. – KABoissonneault Jun 15 '16 at 15:30
  • 1
    @UjjwalAryan Inefficient if you just want to store bytes. However, perhaps there is some theoretical system that uses 32 bits as the smallest memory unit, then you'd have 32 bit bytes. There could be speed benefits to bigger "bytes", at least in the future. –  Jun 15 '16 at 15:32
  • Okay. I have never heard about such systems. Maybe there are. But it does seem a little counter-intuitive though. – Ujjwal Aryan Jun 15 '16 at 15:33
  • [Related](http://stackoverflow.com/q/2098149/179910). – Jerry Coffin Jun 15 '16 at 15:35
  • 1
    AFAIK, there's absolutely nothing special about 8 for the size of a byte... except for the number of programs written that were expecting the size of a byte to be 8 bits. –  Jun 15 '16 at 16:40

0 Answers0