Compatibility between types refers to the similarity of two types to each other. Type compatibility is important during type conversions and operations. All valid declarations in the same scope that refer to the same object or function must have compatible types. Two types are compatible if they fit any of the following categories:
short , signed short
, short int , and signed short int are
the same and are compatible.
unsigned short and unsigned
short int are the same and are compatible.
int , signed , and
signed int are the same and are compatible.
unsigned and unsigned
int are the same and are compatible.
long , signed long ,
long int , signed long int are the same
and are compatible.
unsigned long and unsigned
long int are the same and are compatible.
signed int type.
int tree() ) is compatible with another
function type if the return types are compatible.
int tree (int x) ) is
compatible with another function type declared with a function
prototype if:
tree and
tree2 are compatible. tree and
tree1 are not compatible, and tree1
and tree2 are not compatible.
int tree (int);
int tree1 (char);
int tree2 (x)
char x; /* char promotes to int in old-style
function parameters, and so is
compatible with tree */
{
...
};
The following types, which may appear to be compatible, are not:
unsigned int and int types are
not compatible.
char , signed char , and
unsigned char types are not compatible.
A composite type is constructed from two compatible types and is compatible with both of the two types. Composite types satisfy the following conditions:
Consider the following file-scope declarations:
int f(int (*) (), double (*) [3]); int f(int (*) (char *), double (*)[]);
They result in the following composite type for the function:
int f(int (*) (char *), double (*)[3]);
The previous composite type rules apply recursively to types derived from composite types.