Hacker News new | ask | show | jobs
by mbel 3289 days ago
A slightly related note: you can get similar behavior in C (and C++) with compiler extensions. In GCC and clang marking function with '__attribute__((warn_unused_result))' will produce a warning if function is called without using the result. Equivalent for MSVC is '_Check_return_'.

Obviously this is not nearly as convenient as your Rust example, but enables some of its the benefits.

1 comments

C++17 has (will have?) [[nodiscard]] with the same semantics.