[C++11: 1.7]
talks about bytes in terms of bits:
The fundamental storage unit in the C++ memory model is the byte. A byte is at leas
I'm going to disagree with the accepted answer, since that is emulatable by a ternary machine, which is expressly allowed by the spec.
§ 3.9.1/4 Unsigned integers, declared unsigned, shall obey the laws of arithmetic modulo 2n where n is the number of bits in the value representation of that particular size of integer.
§ 1.8/5 An object of trivially copyable or standard-layout type (3.9) shall occupy contiguous bytes of storage.
§ 3.9/9 Arithmetic types (3.9.1)... are collectively called scalar types. Scalar types, ... arrays of such types... are collectively called POD types. Scalar types ..., arrays of such types... are collectively called trivially copyable types.
§ 3.8/2 For any object... of trivially copyable typeT
, whether or not the object holds a valid value of typeT
, the underlying bytes making up the object can be copied into an array ofchar
orunsigned char
. If the content of the array ofchar
orunsigned char
is copied back into the object, the object shall subsequently hold its original value.
The problem here is that at all points, the state of all trivially copiable multibyte objects must be copiable to an array of char
and back without loss. This means that a ternary machine emulating a base 2 machine (as is required by the basic arithmetic types having modulo "rollovers"), must emulate those rollovers from each emulated byte to the next in each and every unsigned multibyte arithmetic operation.
Even this is emulatable on a ternary machine, slowly, but if all primitive types are made of exactly 41 trits than all a compiler has to worry about is unsigned rollover/under, which might be viable. (Obviously, emulating ^
, |
and &
is also slow, but that's less of an issue in my mind)I think it could be done, but is amazingly impracticable to make a standard conforming C++ compiler for a ternary machine.