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

dsp_module

#1

why?

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

#2

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…


#3

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


#4

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


#5

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


#6

There are performance reasons to avoid unsigned as well.


#7

@jules can we have signed types?


#8

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