Why does the dsp-module uses unsigned types for sample/channel indexes?




  • all other juce routines using signed integers
  • signed types are better for any kind of offset calculation, with results below 0


I can only speculate, but all containers use unsigned int as indices, so might be a performance decision(?)
and by using unsigned int you cannot accidentally read before a buffer (had to find that out the hard way).
But if you overflow value range, it is a disaster anyway…

But yes, your second argument struck me also quite often…


and also these kind of of jasserts will not fire if its overflown
jassert (startSample < numSamples);


FWIW, Stroustrup & Sutter on the topic convinced me here, e.g. https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es107-dont-use-unsigned-for-subscripts


so probably, the signed variant of size_t, ssize_t is the better choice


There are performance reasons to avoid unsigned as well.


@jules can we have signed types?


Yes, I agree that the types should probably have been signed, we may replace them at some point.