Ben Bacarisse said:
Tim Rentsch said:
Ben Bacarisse said:
[snip]
C requires char to be at least 8 bits, but it can be more. All
other types have to be multiples (including 1) of the size of
char.
That seems to prohibit a four bit type, which would be especially
useful on a four bit processor.
There's no reason a conforming implementation couldn't provide its
own four-bit data types, including arrays of such data types. The
rule that all non-bitfield types must be multiples of 'char' in
width applies only to Standard-defined types, not to types provided
as part of extensions.
Do you mean 6.2.6.1 p2? I.e. this:
Except for bit-fields, objects are composed of contiguous sequences of
one or more bytes, the number, order, and encoding of which are either
explicitly specified or implementation-defined.
If so, how can a 4-bit object be exempt; or would the implementation
somehow avoid making these things objects?
Surely this is an easy question to answer. If a variable having
a hitherto unknown datatype is stored in a region of memory, what
difference does it make whether we call that region of memory an
"object" or a "nobject"? The "objectness" of a region of memory
has no meaning except insofar as it implies properties for some
semantic entities defined in part with reference to the term.
As long as those entities have the specified properties, there's
no way of knowing what terminology the implementors use when
talking among themselves about the implementation; it doesn't
matter whether they call everything an object, or distinguish
between "objects" and "nobjects", etc.
I thought you were making a more interesting point than that
almost anything is allowed. The standard permits almost any
extension so you could, for example, have a list type. Such
things would not be objects which is good in that it means they
are not constrained by what the standard says about objects
(their representation, lifetime, derived types, access rules and
so on) but it means you have simply grafted on a new sub language
and everything about that new language and the rest of standard C
must now be specified.
Any extension that introduces new data types has to specify their
semantics. What makes 4-bit types interesting is that they can
be defined in a way so as to be almost indistinguishable from
regular C integer types. It may take some doing to give those
specifications relative to the terminology used in the Standard,
but the resulting language looks so much like C that most people
would hardly know the difference.
The same is true for 4-bit types. They are not prohibited but
they don't fit, so you have to specify almost everything about
them.
This doesn't seem that hard to me. "The data type 'nibble' is a
4-bit value similar to standard C integer data types. A region
of memory that may provide storage for values of this type is
called a /nobject/. The rules for nobjects are the same as the
rules for objects in standard C except ... . The semantics of
operators of expressions having operands of type nibble are the
same as they are for standard C integer types, except ... . The
rules for types derived from type nibble are the same as the
rules for derived types in standard C, except ... ." And so
forth.
Granted, what the differences are between "nobjects" and "objects"
needs to be spelled out carefully and in detail. But mostly how
everything works for nibbles/nobjects is just the same as regular
C types and objects, and that part of the specification can be
done simply by referencing corresponding parts of the Standard,
along the lines of the example above.