7 Strict type checking

Both C99 and C++98 have about the same type checking strictness. Although the original K&R C has very loose type checking, the newer standards make C a strongly-typed language.

Generally speaking, C and C++ does not let you use one type when another type is expected. The exceptions to this rule can be summarized as follows:

Note that C and C++ both consider the following two named structures different:

struct X
{
};

struct Y
{
};

Despite both structures have no members (and hence structurally identical), X and Y are still considered different types. Consequently, the following code generates a warning:

struct X *pX;
struct Y *pY;

// ...
pX = pY;

Copyright © 2006-08-29 by Tak Auyeung