November 18, 2006 What is a void main() that returns a value? | ||||
|---|---|---|---|---|
| ||||
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 Re: What is a void main() that returns a value? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Pierre Rouleau | "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". | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply