@noreturn property

Iain Buclaw ibuclaw at ubuntu.com
Thu Oct 21 10:37:43 PDT 2010


== Quote from Rainer Deyke (rainerd at eldwood.com)'s article
> 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'.

Not sure what you mean when you say that void has only one possible value. To me,
'void' for a function means something that does not return any value (or result).
Are you perhaps confusing it with to, lets say an 'int' function that is marked as
noreturn?

Regards
Iain


More information about the Digitalmars-d mailing list