@noreturn property
Rainer Deyke
rainerd at eldwood.com
Thu Oct 21 10:21:10 PDT 2010
On 10/21/2010 05:54, Iain Buclaw wrote:
> @noreturn void fatal()
> {
> print("Error");
> exit(1);
> }
> Thoughts?
This looks wrong to me. 'fatal' returns type 'void', except that it
doesn't. I would prefer this:
null_type fatal()
{
print("Error");
exit(1);
}
Here 'null_type' is a type that has no values, as opposed to 'void'
which has only one possible value. No variables may be declared of type
'null_type'. A function with a return type of 'null_type' never returns.
Either way would work (and this feature is definitely useful), but
'null_type' has some significant advantages:
- It can be used in delegates and function pointers.
- It can be used in generic code where you don't know if a function
will return or not.
- It makes for more concise code.
Feel free to think of a better name than 'null_type'.
--
Rainer Deyke - rainerd at eldwood.com
More information about the Digitalmars-d
mailing list