From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,8efdde8dbda1f572 X-Google-Attributes: gidfee84,public From: Jeff Sullivan Subject: Re: cc's func prototypes not ANSI? Date: 1999/04/13 Message-ID: <37136ADF.8143A388@zk3.dec.com>#1/1 X-Deja-AN: 465931922 Content-Transfer-Encoding: 7bit References: <371363AC.FB48E8A4@zk3.dec.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Compaq Computer Corporation Mime-Version: 1.0 Newsgroups: comp.unix.osf.osf1 Below is some of the analysis from our ANSI experts: In ANSI 3.1.2.5 (ISO 6.1.2.5) Types, we have "An array type describes a contiguously allocated nonempty set of objects with a particular member object type called the element type." This is footnoted to say that since object types do not include incomplete types, an array of incomplete type cannot be constructed. In the particular case of parameter declarations, 3.5.4.3 Function declarators (including prototypes) says that "For each parameter declared with function or array type, its type for these comparisons is the one that results from conversion to a pointer type, as in 3.7.1". 3.7.1 Function definitions says that "A declaration of a parameter as array of type shall be adjusted to pointer to type." So when analyzing the type compatibility of a function declared "int foo(int i[]);", the type is first adjusted to "int foo(int (*i));". Similarly, analyzing "int foo(int i[][]);" would involve adjustment to "int foo(int (*i)[]);" - the parameter is a pointer to an incomplete array type. 3.1.2.6 Compatible type and composite type includes an example showing that a parameter that is a pointer to an incomplete array type can participate in forming a composite type with the array type completed, as in the pair of declarations: int f(double (*)[]); int f(double (*)[3]); We certainly allow: int y(char (*)[]); int y(char z[3][2]){ return 0; } and so I think we also ought to allow the equivalent: int y(char [][]); int y(char z[3][2]){ return 0; } But you only get the outermost array syntax converted to a pointer. A declaration with three dimensions like "int foo(int a[][][]);" is adjusted to "int foo(int (*a)[][]);" which is a pointer to an incomplete array of incomplete element type, which is not allowed. However, I notice that gcc -ansi -pedantic silently accepts this construct as well. -- Jeff Sullivan | Compaq Computer Corp | mailto:jps@zk3.dec.com DEC C and C++ | Nashua, NH ZK3-2/X29 | Jeff.Sullivan@compaq.com