I’m really confused, in the Primitives.kt file in ...
# announcements
h
I’m really confused, in the Primitives.kt file in the kotlin stdlib, the minus function for Bytes is as follows:
Copy code
/** Subtracts the other value from this value. */
    public operator fun minus(other: Byte): Int
Note: This is inside the byte class.
g
This file used for code generation and will be replaced by actual implementation.
h
it gives me an error when I attempt to do
someByte - 10.toByte()
g
What kind error?
h
expecting byte, but got integer
g
h
but this does not: https://pl.kotl.in/ryEmTJd2m
g
Sure, because byte operators return
int
Sorry, just now got your question
yeah. byte operators produce ints to avoid problems with overflow of byte
same for Java, C# (and maybe other languages)
Just curious, what is your use case with bytes?
h
just using instead of ints, to save memory. im working on native with little memory avialable
g
save memory? How?
Most probably you have 32 bit CPU. so those bytes converted to int anyway
you can save memory with bytes only if have byte array (or value types which don’t available on Kotlin), but not for single byte variable
h
Alright. I'll just use an int
g
If for some reason you still need byte, just convert it explicitly (which means that you know about possible overflow problem) https://pl.kotl.in/HJUexed37
h
thanks!
s
Premature optimization is the root of all evil