Comment #0 by bearophile_hugs — 2014-07-07T09:30:44Z
void main() pure {
import core.stdc.stdio: sprintf;
char[30] buf;
sprintf(buf.ptr, "%d", 1257);
}
dmd 2.066beta1 gives:
test.d(4,12): Error: pure function 'D main' cannot call impure function 'core.stdc.stdio.sprintf'
I think sprintf should be tagged as weakly pure.
Comment #1 by hsteoh — 2014-07-15T15:19:56Z
The problem is that the compiler has no way to verify that sprintf is pure. (In fact, I have doubts whether it is truly pure! You'll be shocked at what C library implementations do under the hood.)
Comment #2 by bugzilla — 2019-12-08T12:48:35Z
sprintf can't be pure, because it has to query the current rounding state of the processor (and queries some internationalization stuff too).