[comp.lang.c++] A different question of NULL, pointers and arrays

ronen@cit-vax.Caltech.Edu (Ronen Barzel) (03/22/90)

In cfront 2.0, the constant 0 will not be automatically
cast to an array type.  For example:

	void f(int y[]);

	void g()
	{
	    f( (int[]) 0 );	// ok
	    f( (int*) 0 );	// ok
	    f(0);	// bad argument 1 type for f(): zero (int [] expected)
	}

And similarly for default initializers -- void f(int y[] = 0); // bad...
If "f" is declared as f(int *y), all these cases work just fine.

According to the AT&T 2.0 Ref Manual, sec 8.2.4:

    "...the constant expressions that specify the bounds of the arrays
    may be missing only for the first member of the sequence.... This
    elision is useful for function arguments of array types...",

and sec 4.6:

    "The following conversions may be performed...
	A constant expression that evaluates to 0 is converted to a pointer...
	An expression with type 'array of T' may be converted to a pointer..."

These two quotes don't imply an automatic conversion of 0 to an array
type for function arguments.  Nor do they imply conversion of a pointer
to an array type, although that seems to be happening in the second case
case.  But, then again, Lippman's interpretation is, sec 3.8:

    "    void putValues( int[ 10 ] );
    is treated by the compiler as having been declared as
	 void putValues( int* );
    ... The following three declarations are equivalent:
	 // three equivalent declarations of putValues
	 void putValues( int* );
	 void putValues( int[] );
	 void putValues( int[ 10 ] );"

If Lippman's interpretation is followed, and the array/ptr
declarations are equivalent, then indeed 0 should be allowed as a
function argument without an explicit cast.  This would be preferable IMHO.

Well, language lawyers, is cfront "correct" as it stands?  Is Lippman
being slighly sloppy in his use of the word 'equivalent'?  Which
relevant passages have I overlooked?

-Ronen

ark@alice.UUCP (Andrew Koenig) (03/23/90)

In article <14377@cit-vax.Caltech.Edu>, ronen@cit-vax.Caltech.Edu (Ronen Barzel) writes:

> In cfront 2.0, the constant 0 will not be automatically
> cast to an array type.

It's a bug, fixed in 2.1
-- 
				--Andrew Koenig
				  ark@europa.att.com