Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Search - "static_cast"
-
What's wrong with this code?
std::pair<float, float> foo() { return { 0, 0 }; }
"Nothing," would you say.
That's because you're normal.
But the most stupid C++ compiler ever (M$ VS)
issues an ERROR that converting 0 to float incurs possible "loss of data". So you have to write "0.f".
BTW, "0." is a double, so you really have to write "0.f". Or "static_cast<float>(0)" if you like ugly, impossible-to-read code.16 -
Let he who is without sin static_cast<Projectile>(firstStone);
I’m not gonna pretend I’ve never forgotten about a small placeholder in my UI, but do I win something for finding this?3 -
Whoever put the hundreds of static_cast<T *>(p) followed by nullptr-checks in the code I am working on: Someday I will find you and then I beat you to death with a hardcover version of "C++ for dummies"!1
-
Sometimes I just can't be arsed to write static_cast<> () and go crazy and use a c cast. What a risk taker I am.1
-
The heck is wrong with the testing framework. I can obviously see that it a correct value why doesn't the test case pass.
FAILED:
REQUIRE( positive==static_cast<double>(0.7352941176) )
with expansion:
0.7352941176 == 0.7352941176
===============================================================================
test cases: 1 | 1 failed
assertions: 1 | 1 failed10