4 ms·
It warns if you add -Wconversion. Unfortunately, that flag generates lots of false positives (at least in gcc), so using it isn't always a good idea.
by xeeeeeeeeeeenu 5y ago
It warns if you add -Wconversion. Unfortunately, that flag generates lots of false positives (at least in gcc), so using it isn't always a good idea.
- jeffbee 5y agoIt isn't ever a good idea. C programmers are just supposed to know about the conversion and promotion rules, every time they add a line, even though the rules are actually insanely complicated. Compiler warnings can't overcome this because programmers have no way of just discovering one of GCC's 726 warning flags, only a few of which are enabled by -Wall and -Wextra, most of which are way too noisy to serve a useful purpose.
- morio 5y agoWhat kind of false positives are you seeing with gcc? Personally I have never seen gcc spitting out a false positive. IMO it's always a good idea to explicitly downcast even if you know that it's 'safe'. That way someone else will see instantly what's going on. The fact that Rust requires it should tell us something.
- xeeeeeeeeeeenu 5y agoFor example, I've just reported this: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101537 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101537 You can find more cases in the bugtracker. To be fair, it seems many of them were fixed in recent releases.
- Cloudef 5y agoThe 1 and 0 are ints. It most likely complaints because the sign isn't same.
- ototot 5y agoIn my own small projects, I always add -Wconversion to build configuration. I think the false positive is affordable when you start from small piece of code.