digitalmars.D - Should C functions automatically be nothrow?
- Jonathan M Davis (11/11) Feb 06 2012 Can C functions throw? I don't know of any way that a C function could t...
- Walter Bright (3/4) Feb 06 2012 Yes. There's no reason you cannot write:
- deadalnix (4/15) Feb 07 2012 extern(C) goes in both directions. D can call C, but C can call D. And D...
-
Stewart Gordon
(5/6)
Feb 07 2012
- Timon Gehr (2/9) Feb 07 2012 AVs are not thrown. (if they were, they could be caught.)
- Walter Bright (5/10) Feb 07 2012 Although seg faults are converted into D exceptions on Windows by drunti...
- H. S. Teoh (11/22) Feb 07 2012 [...]
- Johannes Pfau (3/29) Feb 08 2012 Does libsigsegv have the same restrictions or how is it implemented?
- Martin Nowak (7/20) Feb 07 2012 I'm not a big fan of translating async exceptions which causes enough ba...
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
Feb 06 2012
On 2/6/2012 6:04 PM, Jonathan M Davis wrote:Can C functions throw?Yes. There's no reason you cannot write: extern (C) void foo() { throw new Exception(); }
Feb 06 2012
Le 07/02/2012 03:04, Jonathan M Davis a écrit :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 Davisextern(C) goes in both directions. D can call C, but C can call D. And D can throw exceptions. So you can end up with extern(C) function that throw exceptions.
Feb 07 2012
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. Stewart.
Feb 07 2012
On 02/07/2012 02:40 PM, Stewart Gordon wrote:On 07/02/2012 02:04, Jonathan M Davis wrote:AVs are not thrown. (if they were, they could be caught.)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. Stewart.
Feb 07 2012
On 2/7/2012 5:40 AM, Stewart Gordon wrote:On 07/02/2012 02:04, Jonathan M Davis wrote: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. Nor would C code do such a conversion anyway.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.
Feb 07 2012
On Tue, Feb 07, 2012 at 11:53:45AM -0800, Walter Bright wrote:On 2/7/2012 5:40 AM, Stewart Gordon wrote:[...] 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. :) T -- Time flies like an arrow. Fruit flies like a banana.On 07/02/2012 02:04, Jonathan M Davis wrote: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.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.
Feb 07 2012
Am Tue, 7 Feb 2012 12:31:06 -0800 schrieb "H. S. Teoh" <hsteoh quickfur.ath.cx>:On Tue, Feb 07, 2012 at 11:53:45AM -0800, Walter Bright wrote:Does libsigsegv have the same restrictions or how is it implemented?On 2/7/2012 5:40 AM, Stewart Gordon wrote:[...] 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. :) TOn 07/02/2012 02:04, Jonathan M Davis wrote: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.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.
Feb 08 2012
On Tue, 07 Feb 2012 20:53:45 +0100, Walter Bright <newshound2 digitalmars.com> wrote:On 2/7/2012 5:40 AM, Stewart Gordon wrote:I'm not a big fan of translating async exceptions which causes enough bad usage in C++ land. We're translating them to Errors though. Visual C++ allows to switch between different EH models http://msdn.microsoft.com/en-us/library/1deeycx5(v=vs.100).aspx.On 07/02/2012 02:04, Jonathan M Davis wrote: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. Nor would C code do such a conversion anyway.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.
Feb 07 2012