On Thursday, 9 April 2015 at 11:09:43 UTC, John Colvin wrote:
On Thursday, 9 April 2015 at 11:04:00 UTC, Dennis Ritchie wrote:
Hi,
Is it allowed in D similar designs?

void main() {
        import std.stdio;
        return writeln("Hello, world!");
}

Yes, because writeln returns nothing, but why would you do that? Just put the return on the next line, it's more readable. Or, in the example above, just omit it entirely as the return is implicit.

It's useful when writing generic wrappers, where you just want to return whatever the wrapped function returns and don't want to treat void functions differently.

I wouldn't use it in normal code, because it can be confusing, as `return` usually indicates that a value is indeed returned.

Reply via email to