Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!jarthur!elroy.jpl.nasa.gov!cit-vax!ronen From: ronen@cit-vax.Caltech.Edu (Ronen Barzel) Newsgroups: comp.lang.c++ Subject: A different question of NULL, pointers and arrays Message-ID: <14377@cit-vax.Caltech.Edu> Date: 22 Mar 90 06:26:05 GMT Organization: California Institute of Technology Lines: 50 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