Should C functions automatically be nothrow?

H. S. Teoh hsteoh at
Tue Feb 7 12:31:06 PST 2012

On Tue, Feb 07, 2012 at 11:53:45AM -0800, Walter Bright wrote:
> On 2/7/2012 5:40 AM, Stewart Gordon wrote:
> >On 07/02/2012 02:04, Jonathan M Davis wrote:
> >>Can C functions throw? I don't know of any way that a C function could throw.
> ><snip>
> >
> >On top of what the others have said, functions written in C can certainly throw
> >such things as AVs.
> Although seg faults are converted into D exceptions on Windows by
> druntime, and so can be caught, I suspect this was not a good idea.
> It's completely non-portable to other systems.

I was going to suggest using siglongjmp() and doing stack-unwinding in
the SEGV signal handler on Posix systems, but apparently this is very
very evil because subsequent code will still be running in the signal
handler's context and any call to signal-unsafe functions will cause
undefined behaviour.

So yeah. Bad idea. :)


Time flies like an arrow. Fruit flies like a banana.

More information about the Digitalmars-d mailing list