Should C functions automatically be nothrow?

Brad Roberts braddr at puremagic.com
Mon Feb 6 18:10:29 PST 2012


The classic example of when a c function can throw is via callbacks.  For 
example, passing a D function to the c runtime qsort.  If that function 
throws, calling qsort with it can throw.  While libc doesn't have a lot of 
that sort of function, the realm of C code in general is bigger.

That argues for appropriately labeling them since the entire set can't be 
just assumed to be nothrow.  Some of the core.* files have already been 
hit, I believe.

Later,
Brad

On Mon, 6 Feb 2012, Jonathan M Davis wrote:

> Can C functions throw? I don't know of any way that a C function could throw. 
> Is it possible if you have a C function which calls a D function or something 
> like that? I don't know. I wouldn't really expect the C function to be able to 
> handle the D exception, in which case, it wouldn't end up throwing the 
> exception to whatever code calls it.
> 
> Assuming that C functions can't throw, is there any reason _not_ to have the 
> compiler automatically treat C functions as nothrow?
> 
> If we can't treat C funtions in general as nothrow (for whatever reason that 
> may be), is there a reason why we can't explicitly mark the various C bindings 
> in druntime as nothrow at the very least?
> 
> - Jonathan M Davis
> 


More information about the Digitalmars-d mailing list