Ben Bacarisse
5/22/2011 10:03:00 PM
jacob navia <jacob@spamsink.net> writes:
> I am updating my tutorial of C, and I have added a section of type
> classification. Please tell me if I forgot something or said
> something wrong if possible.
I'd add few remarks to what Keith Thompson has said.
> A C type can be either a function type, an incomplete type or an object
> type. Function types can be either fully specified, i.e. we have a
> prototype available, or partially specified with missing arguments but
> a known return value. The function type "implicit int function" with
> return value and arguments unknown, has been declared obsolete in C99.
>
> Incomplete types are unspecified and it is assumed that they will be
> specified elsewhere, except for the void type that is an incomplete
> type that can't be further specified.
Form a style point of view, this listing of terms followed by
definitions (your paragraphs below all start with some category of type)
is not that helpful. Often the definition of a term is the least
interesting thing about it. That's particularly true of incomplete
types. I'd explain them by stating how they often occur:
"It is sometimes helpful to postpone or omit the full specification of a
type. Such a partial definition of an object type gives rise an
incomplete type. The type definition will usually be completed later in
the source file or in another source file where the full details are
finally needed. Until a type is complete, the size of the type is
unknown and objects of the type can't be defined. The type void is
rather special. It is an incomplete type that can never be completed."
> Object types can be either scalar or composite types. Composite types
> are built from the scalar types: structures, unions and arrays. Scalar
> types are of two kinds: arithmetic or pointer types. Pointer types can
> point to scalar or composite types, to functions or to incomplete types.
>
> Arithmetic types have two kinds: integer types and floating types. The
> integer types are either standard integers, bit fields or
> enumerations.
I don't think bit fields are really types. They have a type, but you
can't declare something to have a bit-field type. I'd leave them out
altogether -- I think they are better explained as a special kind of
structure members.
> The standard integer types are boolean, char, short, int, long and long
> long, all with signed or unsigned types, except the boolean type
> that hasn't any sign but is not an unsigned type.
boolean is not a type in C. You could say "bool (the Boolean type)" or
you could use the real type name _Bool, ugly though it is. Also, _Bool
*is* an unsigned type.
Technically, char is not listed as one of the "standard integer types".
"signed char" is one and so is the unsigned type that corresponds to it,
but char is a third type different to these two. It is included in the
group called "integer types". The problem is that the term "standard
integer type" is used to distinguish these types form "extended integer
types". If you dropped the word "standard" from that paragraph, there
would be not possibility of confusion.
> Floating types are either real or complex, with both of them appearing
> in three flavors: float, double and long double.
--
Ben.