www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - noreturn ?

reply bearophile <bearophileHUGS lycos.com> writes:
C1X (C11), the successor of C99, is now designed, among its changes there is
_Noreturn, this is what the latest free draft says about it:

A function declared with a _Noreturn function specifier shall not return to its
caller.
The implementation should produce a diagnostic message for a function declared
with a _Noreturn function specifier that appears to be capable of returning to
its caller.


_Noreturn void f () {
    abort(); // ok
}
_Noreturn void g (int i) { // causes undefined behavior if i<=0
    if (i > 0) abort();
}



#include <setjmp.h>
_Noreturn void longjmp(jmp_buf env, int val);


#include <stdlib.h>
_Noreturn void abort(void);


#include <stdlib.h>
_Noreturn void exit(int status);


#include <stdlib.h>
_Noreturn void _Exit(int status);


#include <stdlib.h>
_Noreturn void quick_exit(int status);

GNU C has a noreturn attribute since a lot of time. I don't fully understand
why such attribute is so useful in C programs, but is something like a
 noreturn function attribute useful in D too? Maybe to implement a better halt
assert(0)?

Bye,
bearophile
Dec 24 2011
next sibling parent reply "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Saturday, 24 December 2011 at 20:09:46 UTC, bearophile wrote:
 GNU C has a noreturn attribute since a lot of time. I don't 
 fully understand why such attribute is so useful in C programs, 
 but is something like a  noreturn function attribute useful in 
 D too? Maybe to implement a better halt assert(0)?

How about: scope(success) assert(0); ?
Dec 24 2011
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 12/24/2011 06:58 PM, Vladimir Panteleev wrote:
 On Saturday, 24 December 2011 at 20:09:46 UTC, bearophile wrote:
 GNU C has a noreturn attribute since a lot of time. I don't fully
 understand why such attribute is so useful in C programs, but is
 something like a  noreturn function attribute useful in D too? Maybe
 to implement a better halt assert(0)?

How about: scope(success) assert(0); ?

The attribute should be migrated to the signature of the function such that calling code can take advantage of it. I personally think this is a small matter. Right now we have bigger rocks to move. It would be great if 2.058 had all [tdpl] bugs fixed. Andrei
Dec 24 2011
prev sibling next sibling parent Caligo <iteronvexor gmail.com> writes:
--bcaec5040c0ecd39c804b4e03518
Content-Type: text/plain; charset=ISO-8859-1

On Sat, Dec 24, 2011 at 2:09 PM, bearophile <bearophileHUGS lycos.com>wrote:

 I don't fully understand why such attribute is so useful in C programs

 Bye,
 bearophile

Functions are like people. Sometimes they go places that's so beautiful that they never want to return. --bcaec5040c0ecd39c804b4e03518 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <br><br><div class=3D"gmail_quote">On Sat, Dec 24, 2011 at 2:09 PM, bearoph= ile <span dir=3D"ltr">&lt;<a href=3D"mailto:bearophileHUGS lycos.com">bearo= phileHUGS lycos.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quo= te" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"=

ams<br> <br> Bye,<br> <span class=3D"HOEnZb"><font color=3D"#888888">bearophile<br> </font></span></blockquote></div><br><div>Functions are like people. =A0Som= etimes they go places that&#39;s so=A0beautiful that they never want to ret= urn.</div> --bcaec5040c0ecd39c804b4e03518--
Dec 24 2011
prev sibling parent "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Saturday, December 24, 2011 22:26:02 Andrei Alexandrescu wrote:
 On 12/24/2011 06:58 PM, Vladimir Panteleev wrote:
 On Saturday, 24 December 2011 at 20:09:46 UTC, bearophile wrote:
 GNU C has a noreturn attribute since a lot of time. I don't fully
 understand why such attribute is so useful in C programs, but is
 something like a  noreturn function attribute useful in D too? Maybe
 to implement a better halt assert(0)?

How about: scope(success) assert(0); ?

The attribute should be migrated to the signature of the function such that calling code can take advantage of it. I personally think this is a small matter. Right now we have bigger rocks to move. It would be great if 2.058 had all [tdpl] bugs fixed.

It's the sort of thing that we could add at any time without breaking backwards compatibility, so there's no rush unless it solves a burning problem. But at best, it solves a minor inconvenience. Solving the TDPL on the other hand would resolve a major usability issue for the language - particularly how it affects newbies reading TDPL. But completely aside from the newbies, it's a major milestone in actually having the full language implemented so that there's a lot less of a distinction between the design and the implementation. - Jonathan M Davis
Dec 25 2011