Casting std::atomic<float>* variables

Hello, I’m still new to JUCE, so please forgive me if this isn’t a good question!

I’m running on v5.4.7 and tried compiling a v5.4.6 project recently. There were some float* variables assigned from getRawParameter() and it threw me an error about the floats, so I changed them to std::atomic<float>*.

I saw this commit as well:

The problem is, there was somewhere else in the code where the developer tried to cast it to an int with roundToInt() from the JUCE core (the problem was specifically with line 478 of juce_MathsFunctions.h) saying something about not being able to cast it?

Can an atomic float be cast to anything? Should it be? How should I handle it if I want to make it into an int?

Sorry if this doesn’t make sense, or if it’s a simple mistake!

Just to clarify terminology, roundToInt() is not a cast, it is a function that rounds a float to an int, and returns an int. Having said that, roundToInt (yourAtomicFloat.load()); should do the trick.

1 Like

I see, thank you for the clarification! I’ll see if I can try using the load function later today and post back with results.

Thanks again!

N.B. if you are talking about the return value of getRawParameterValue, since it is a pointer to the std::atomic, simply use -> instead of .
And consider keeping the pointer as member variable, that saves you the lookup each processBlock() call.

1 Like

Hello Daniel, thank you! I went with var.atomicFloat->load(); and that worked!
Thank you for the member variable advice too.

Thank you for the advice! I used the load() function and that worked out just fine!