endail / hx711

Raspberry Pi HX711 C++ Library
MIT License
18 stars 10 forks source link

std::chrono::high_resolution_clock use is ambiguous #47

Closed endail closed 2 years ago

endail commented 2 years ago

https://en.cppreference.com/w/cpp/chrono/high_resolution_clock

The high_resolution_clock is not implemented consistently across different standard library implementations, and its use should be avoided. It is often just an alias for std::chrono::steady_clock or std::chrono::system_clock, but which one it is depends on the library or configuration. When it is a system_clock, it is not monotonic (e.g., the time can go backwards). For example, for gcc's libstdc++ it is system_clock, for MSVC it is steady_clock, and for clang's libc++ it depends on configuration.

Generally one should just use std::chrono::steady_clock or std::chrono::system_clock directly instead of std::chrono::high_resolution_clock: use steady_clock for duration measurements, and system_clock for wall-clock time.

https://github.com/endail/hx711/search?q=high_resolution_clock shows it being used in contexts where a steady clock (ie. std::chrono::steady_clock) should explicitly be used.