Tentative defs, type compatibility.

Kenneth Almquist ka at june.cs.washington.edu
Tue May 30 20:00:19 AEST 1989


am at cl.cam.ac.uk (Alan Mycroft) writes:
> Consider the following dpANS C program:
>    int x[10];
>    int x[] = { 1,2 };
> Does the x[10] and x[] get unified together before the initialisation of
> x[10] to {1,2,0,0,...} or does the initialisation of x to (int[2]){1,2}
> happen first and cause a type conflict with x[10]?

In traditional C, the latter.  From K&R Edition 1, page 195:

	The first constant-expression [i.e. the expression in the
	leftmost "[]" in an array declaration] may also be omitted
	when the declarator is followed by initialization.  In this
	case the size is calculated from the number of initial
	elements supplied.

This is useful when an array is declared in a header file and initialized
in a C file.  By omitting the array size from the initialization, you can
have the compiler check that you gave the right number of initializers.

The lack of clarity in the dpANS suggests that X3J11 did not intend to
differ from traditional C.  As Doug Gwyn notes in <10330 at smoke.BRL.MIL>,
the only way to be sure is to submit a query to X3J11.
					Kenneth Almquist



More information about the Comp.std.c mailing list