Today i stepped into this code snippet:
classdef (Enumeration,Sealed) ClassBlabla < int8
enumeration
ALPHA(0)
BETA(1)
GAMMA(2)
end
methods (static)
function ret = doSomething()
ret = containers.Map(.......)
for i = int32(ClassBlabla.ALPHA):int32(ClassBlabla.GAMMA)
ret(i) = somethingelse(blablabla(i))
end
end
end
end
What is that int32(...) in the for?? A cast? Why do I want to cast to int32? Isn't ALPHA already 0 and GAMMA already 2??
It's to widen the ALPHA and GAMMA values fro int8 to int32. Most likely, that's because either the blablabla() function expects an int32 input, or the ret value is expected to have int32 keys. ALPHA and GAMMA are already 0 and 2, but they are int8 instead of int32, and blablabla() or clients of doSomething() may not play well with int8 values. (You can tell ALPHA and GAMMA are int8 because of the ClasBlabla < int8 at the top.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With