[phobos] Purity of C Math Functions
Jonathan M Davis
jmdavisProg at gmx.com
Sun Dec 5 18:54:35 PST 2010
On Sunday 05 December 2010 15:51:07 Simen Kjaeraas wrote:
> Jonathan M Davis <jmdavisProg at gmx.com> wrote:
> > On Sunday 05 December 2010 08:55:54 David Simcha wrote:
> >> I'm trying to test out Brad's 64 work and I can't compile Phobos because
> >> in 64 mode std.math calls some C math functions declared in druntime w/o
> >> purity, safety, etc. tags. I now remember that this was one of the few
> >> areas I meant to come back to when I was cleaning up 64 support in
> >> Phobos, but I forgot about it. Is it safe to assume that C
> >> core.stdc.math functions are @safe pure nothrow?
> >
> > Shouldn't _all_ C function be considered nothrow? C doesn't have
> > exceptions, so
> > C functions can't possibly throw.
>
> A C function could call a D function (e.g. passed as a function pointer),
> no?
Well, I wouldn't expect a D function which threw an exception to be properly
handled by the C function, such that it would be an extremely bad idea to call a
D function which throws from C code. I certainly wouldn't expect calling a C
function which calls a D function to throw an exception even if the D function
threw one. I'd expect things to go seriously south if a D function ever threw an
exception and a C function called it. Maybe it's able to handle it somehow. I
don't know. But I wouldn't expect it to work, since C has no concept of
exceptions.
- Jonathan M Davis
More information about the phobos
mailing list