6.2.7 Compatible type and composite type

Previous Table of Contents "New C Standard" commentary

631 Two types have compatible type if their types are the same.

632 Additional rules for determining whether two types are compatible are described in 6.7.2 for type specifiers, in 6.7.3 for type qualifiers, and in 6.7.5 for declarators.46)

633 Moreover, two structure, union, or enumerated types declared in separate translation units are compatible if their tags and members satisfy the following requirements:

634 If one is declared with a tag, the other shall be declared with the same tag.

635 If both are complete types, then the following additional requirements apply:

636 there shall be a one-to-one correspondence between their members such that each pair of corresponding members are declared with compatible types, and such that if one member of a corresponding pair is declared with a name, the other member is declared with the same name.

637 For two structures, corresponding members shall be declared in the same order.

638 For two structures or unions, corresponding bit-fields shall have the same widths.

639 For two enumerations, corresponding members shall have the same values.

640 All declarations that refer to the same object or function shall have compatible type;

641 otherwise, the behavior is undefined.

642 A composite type can be constructed from two types that are compatible;

643 it is a type that is compatible with both of the two types and satisfies the following conditions:

644 —  If one type is an array of known constant size, the composite type is an array of that size;

645 otherwise, if one type is a variable length array, the composite type is that type.

646 —  If only one type is a function type with a parameter type list (a function prototype), the composite type is a function prototype with the parameter type list.

647 —  If both types are function types with parameter type lists, the type of each parameter in the composite parameter type list is the composite type of the corresponding parameters.

648 These rules apply recursively to the types from which the two types are derived.

649 For an identifier with internal or external linkage declared in a scope in which a prior declaration of that identifier is visible,47) if the prior declaration specifies internal or external linkage, the type of the identifier at the later declaration becomes the composite type.

650 46) Two types need not be identical to be compatible.

651 47) As specified in 6.2.1, the later declaration might hide the prior declaration.

652 EXAMPLE Given the following two file scope declarations:


        int f(int (*)(), double (*)[3]);
        int f(int (*)(char *), double (*)[]);

The resulting composite type for the function is:


        int f(int (*)(char *), double (*)[3]);

Next

Created at: 2008-01-30 02:39:41 The text from WG14/N1256 is copyright © ISO