mpusz / mp-units

The quantities and units library for C++
https://mpusz.github.io/mp-units/
MIT License
994 stars 79 forks source link

Is mp-units targeting freestanding implementations #556

Closed kwikius closed 1 month ago

kwikius commented 4 months ago

As title . I work mainly on embedded systems, which are typically freestanding . Is mp-units going to require a hosted implementation?

mpusz commented 4 months ago

Sure, freestanding is our target as stated here https://wg21.link/p3045#low-standardization-cost and as I explicitly said several times before (https://github.com/mpusz/mp-units/discussions/406, https://github.com/mpusz/mp-units/issues/7).

kwikius commented 4 months ago

Sure, freestanding is our target as stated here https://wg21.link/p3045#low-standardization-cost and as I explicitly said several times before (#406, #7).

OK. Apologies. I have not followed mp-units for a while. That is reassuring, but slightly vague. Ideally I would hope for the full functionality but without major IO overhead , though in practise some diagnostic output in a simple format is always going to be required.

mpusz commented 4 months ago

Initially, we tried to isolate IO as much as possible (separate CMake targets, separate C++ modules, etc.), but it didn't scale. I consulted the best freestanding experts in the ISO Committee on how to proceed, and they said to do the same as a C++ standard library does. If needed, we will provide preprocessor logic to limit functionality for freestanding if such is requested by the users.

in practise some diagnostic output in a simple format is always going to be required.

Sure, this is why we expose the following functions that should help build a custom mechanism without the need to include streams or formatting facilities:

https://github.com/mpusz/mp-units/blob/792bd2c191d3d936070dad9d098716b78ea35193/src/core/include/mp-units/unit.h#L840-L841

https://github.com/mpusz/mp-units/blob/792bd2c191d3d936070dad9d098716b78ea35193/src/core/include/mp-units/unit.h#L860-L861

kwikius commented 4 months ago

I will try to get back to testing mp-units. In embedded environment absolute limit is the amount of rom available on the microcontroller. The smaller the footprint of the library, the bigger the range of microcontroller a library will run on. nyway don't underestimate the microcontroller side. It is a large user base and could find mp-units very useful, but don't make anything like as much noise as others ;)

mpusz commented 4 months ago

This would be great @kwikius! As of now we don't use any conditional compilation for freestanding. We need to decide if we should introduce custom flags or use those used by the compiler vendors. But we need some for sure and we need some testing on embedded environments as well.

mpusz commented 4 months ago

More info on text output can be found in https://mpusz.github.io/mp-units/2.2/users_guide/framework_basics/text_output/#derived-unit-symbols-generation