On Thursday, 11 January 2018 at 11:19:41 UTC, Robert M. Münch wrote:
On 2018-01-08 22:16:25 +0000, rumbu said:

This is my first D finalized project (+16k loc).

Great stuff! Will this work in betterC mode?


It will not work without some refactory. Most of phobos/druntime dependencies are minimal an can be rewritten - in fact there are only 9 dependencies: bsr, bsf, addu, subu, adds, subs from druntime and isNaN, isinfinity, signbit from std.math.

The rest of the dependencies are simply traits that must work by default under betterC.

Once dependencies are solved, another problem will be the exception mechanism. 90% of arithmetic operations are meant to throw exceptions, but this can be overridden by the alternate exception handling - raising and setting flags.

BUT - a very big but - the most important issue is the formatting thing. Even there is no direct dependency on std.format or std.stdio, the formatting mechanism is designed to fit nicely into phobos formatting paradigm. That means that there is no way to output decimal values on the console without phobos. I confess that 30% of my development time was the formatting feature: displaying correctly any possible combination of width, padding, alignment in 4 different formats (%f, %g, %e, %a) was really a challenge and despite of hundreds of unit tests, I'm not convinced today that I covered all the corner cases. The f*cking %g took me 3 days to find out exactly what is meant to do. More than that, each compiler producer have a different idea about format specifiers. Linking your application against snn, msvcrt or glibc will render completely different results for printf("%g", ...). On top of that, neither the FormatSpec documentation from phobos is something complete and clear...

AFAIK, there is no way to plug a custom formatting mechanism into printf, not even in plain C (ok, I'm aware that gcc has something in this respect).

To sum things up, it is possible to use it in betterC mode if:
- all dependencies are rewritten;
- the exception handling is dropped out completely;
- a printf equivalent for decimal types is rewritten from scratch or - decimal values must be converted to binary float before printing them - but this will negate the main purpose of the decimal type - precision.




Reply via email to