errno is not nothrow

H. S. Teoh hsteoh at quickfur.ath.cx
Fri May 11 19:01:05 UTC 2018


On Fri, May 11, 2018 at 12:42:01PM -0600, Jonathan M Davis via Digitalmars-d wrote:
[...]
> In the case of errno, it's coming from core.stdc.errno, and it looks
> like on pretty much every system, it's declared as an alias for an
> extern(C) function - e.g.
> 
> ref int __error();
> 
> and none of them are marked with any attributes. In this particular
> case, I would think that they could be marked with @trusted, nothrow,
> and @nogc. I don't know about pure.  Probably not, but I could see it
> being a treated a bit like floating point flags where pure functions
> are allowed to muck with them even though they're arguably global
> state. So, I don't know.

This sounds scary.  So my (strongly!) pure function that returns
floating-point can return different results when passed the same
parameters, if somebody in between changes floating-point flags?  That
doesn't sound good at all.

	float evil() pure /* ! */ {
		/* change FP flags, like rounding mode or something */
		return 0.0;
	}

	float myfunc(float f) pure { return ...; }

	float result = myfunc(1.23) + evil() + myfunc(1.23);

Since myfunc() is marked pure, the compiler could cache the result of
the first call and reuse it for the second. But since evil() changes FP
flags in between, the result will be different from what would have been
computed had the compiler not cached the return value of the first call.
:-(


T

-- 
Tech-savvy: euphemism for nerdy.


More information about the Digitalmars-d mailing list