Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: Jeff Sullivan <jps@zk3.dec.com>
Subject: Re: cc's func prototypes not ANSI?
Date: 1999/04/13	[thread overview]
Message-ID: <37136ADF.8143A388@zk3.dec.com> (raw)
In-Reply-To: 371363AC.FB48E8A4@zk3.dec.com

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



      parent reply	other threads:[~1999-04-13  4:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-04-13  4:00 cc's func prototypes not ANSI? Jeff Sullivan
1999-04-13  4:00 ` Jeff Sullivan
1999-04-13  4:00 ` Jeff Sullivan [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox