November 18, 2006
With DMD 0.179:

- A void main with no return statement returns 0, a decent choice.
- A void main with a return statement is accepted without warning or compiler error. Is this a bug?



// ------------------
void
main()
{
   return 1;   // returns 1 to the OS
}

// --------BAD--------
void
main()
{
   return 1.0;  // returns 33 to the OS
}

// --------BAD--------
void
main()
{
   return "0123456789";  // returns 48 to the OS
}

--

P.R.





November 18, 2006
"Pierre Rouleau" <prouleau@impathnetworks.com> wrote in message news:ejnhne$2c0r$1@digitaldaemon.com...
> With DMD 0.179:
>
> - A void main with no return statement returns 0, a decent choice. - A void main with a return statement is accepted without warning or compiler error. Is this a bug?
>

Void functions are allowed to have return statements with a return value expression, and main is no exception.  I think it's to remove some special case stuff regarding templated functions.  The expression is evaluated but its value is discarded.  Example:

int foo()
{
 writefln("foo");
 return 0;
}

void bar()
{
 return foo();
}

void main()
{
 bar();
}

prints "foo".