What is a void main() that returns a value?

Jarrett Billingsley kb3ctd2 at yahoo.com
Sat Nov 18 11:58:59 PST 2006


"Pierre Rouleau" <prouleau at impathnetworks.com> wrote in message 
news:ejnhne$2c0r$1 at 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". 





More information about the Digitalmars-d mailing list