6.2.7 Compatible type and composite type

Previous Table of Contents

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

628 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)

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

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

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

632 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.

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

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

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

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

637 otherwise, the behavior is undefined.

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

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

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

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

642 —  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.

643 —  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.

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

645 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.

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

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

648 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: 2005-06-29 02:18:55 The text from WG14/N1124 is copyright © ISO