Audio channels array constness


#1

Hi Jules, I encountered something which looked strange at first sight, when calling AudioFormatWriter::writeFromFloatArrays(); I wanted to feed it with float**, and the compiler bugged me about the difference in constness. I can solve it locally by doing a cast, but there is something which looks smarter to me, please continue reading.

In fact, we can't feed a const float** function parameter with a float** value, this is why: http://c-faq.com/ansi/constmismatch.html

What I find important is the following note:

(C++ has more complicated rules for assigning const-qualified pointers which let you make more kinds of assignments without incurring warnings, but still protect against inadvertent attempts to modify const values. C++ would still not allow assigning a char ** to a const char **, but it would let you get away with assigning a char ** to a const char * const *.)

Looking at the writeFromFoatArrays function signature, I would say that it should rather take a const float * const * parameter, which is more consistent, and would also solve this issue!

All the best!

PS: sorry for the bold, I can't find the <pre> format in this forum.


#2

Ah, good catch, thanks! I've used const float* const* in most other places, but must have missed that one.