Compatible and composite types

C Beginning of C only.

In C, compatible types are defined as:
  • two types that can be used together without modification (as in an assignment expression)
  • two types that can be substituted one for the other without modification

When two compatible types are combined, the result is a composite type. Determining the resultant composite type for two compatible types is similar to following the usual binary conversions of integral types when they are combined with some arithmetic operators.

Obviously, two types that are identical are compatible; their composite type is the same type. Less obvious are the rules governing type compatibility of non-identical types, user-defined types, type-qualified types, and so on. Type specifiers discusses compatibility for basic and user-defined types in C.

C End of C only.

C++ Beginning of C++ only.

A separate notion of type compatibility as distinct from being of the same type does not exist in C++. Generally speaking, type checking in C++ is stricter than in C: identical types are required in situations where C would only require compatible types.

C++ End of C++ only.