A valid function with no return type?

Adam D. Ruppe destructionator at gmail.com
Thu Sep 24 21:31:27 UTC 2020


On Thursday, 24 September 2020 at 21:26:30 UTC, Max Haughton 
wrote:
> Assuming this is supposed to be allowed by the standard,

Yes, this is expected.

So the `auto` keyword in D is actually a do-nothing placeholder. 
It just indicates to the grammar that a declaration is coming. 
Any other keyword that is only valid in declarations does the 
same job and then implies `auto`.

In local variables it is often common to see like

const a = 5;

And in function declarations, a variety of things triggers the 
same thing including pure, ref, @safe, or even user-defined 
attributes. Just enough to tell the compiler a function is 
coming, then it assumes `auto` return until it sees a concrete 
type instead.

> replacing void with ref (i.e. ref main { ) does not compile 
> which suggests something isn't right.

main is special, it must have a specific signature to be 
registered.


More information about the Digitalmars-d mailing list