Hi, I´m learning here, doing the tutorials, and I’m seeing an awfull amount of (float) , (unsigned int) (int) (double) etc. casting everywhere. Just a few of them seem to have a real mathematical purpose, almost all of them I can remove them and everything runs the same …
Why is juce using so many casting ? Isn’t this type of casting non recommended in c14++ ?
I guess the Juce developers do not use linting tools… I find it quite ugly and a bad example for new developers. Should not be removed but replaced with correct C++ casts imho.
With a modern compiler and sensible warnings settings, you will get warnings when you remove them, and rightfully so.
I agree, they should be modernised with safer versions of casts like static_cast. I would believe they do whenever they touch code around, but that’s for the JUCE team to say.
From our coding standards
Avoid C-style casts except when converting between obviously primitive numeric types. Some people would say “avoid C-style casts altogether”, but writing static_casts can be a bit long-winded when you just want to trivially cast an int to a float. But whenever a pointer or template or non-primitive type is involved, always use modern casts. And when you’re reinterpreting data, always use reinterpret_cast.
I think in most of the examples it’s probably casting between primitive numeric types. Could you possibly share some examples that you think are particularly problematic?
I dont think any are “problematic”, I was just asking about why the style of programming was involving so many castings.
Was reading the Tutorial: Wavetable synthesis and it has a lot of casting, I will continue to study the hiden purpose of every cast in particular.
Thanks for your answer !
