www.digitalmars.com         C & C++   DMDScript  

D - no error on missing return value [beta 0.58]

reply "Mike Wynn" <mike.wynn l8night.co.uk> writes:
Walter,
I though this had been fixed, or has it been fixed such that no return value
means <return-type>.init
strangely
 printf( " null   -> %.*s", foo === null ? foo : "null" ); // 3 '=' works
 printf( " null   -> %.*s", foo ? foo : "null" );  // causes access
violation

I has assumed that  bar = foo ? foo : "null"; would be the same as
if( foo ) bar = foo; else bar = "null";
or
if( foo !== null ) bar = foo; else bar = "null"; // !2'='

-------------------------------------------------------------------
import c.stdio;

char[] func( int[] foo ){
 char[] rv;
 int i = 0;
 if ( foo )
  while( i < foo.length ) {
   i+=foo[i];
   if ( i > foo.length ) { return rv; }
   rv ~= "A";
  }
}

int[] nums = [1,2,3,4];

int main( char[][] argv )
{
 char[] foo = func( nums );
 printf( "1,2,3,4 -> %.*s", foo );
 foo = func( null );
// printf( " null   -> %.*s", foo ? foo : "null" ); access violation
 printf( " null   -> %.*s", foo === null ? foo : "null" );
 return 0;
}
Mar 07 2003
parent "Walter" <walter digitalmars.com> writes:
I'll check it out. -Walter
Mar 07 2003