Is anyone else experiencing odd behavior across pl...
# kotlin-native
m
Is anyone else experiencing odd behavior across platforms? on linux, kotlin/native assumes an
unsigned long
is a ULong, but on windows it's parsed as
UInt
r
I don't know about
unsigned long
on those platforms in particular but it is common for k/n platforms with different integer widths to map numerical types differently
m
So what should I do to make my code work cross-platform in a way that doesn't require me to maintain multiple branches?
r
One way is to add `expect`/`actual` declarations around your interactions with variable-width types. There's also a
convert()
function which can help but if you're not careful you can lose information because it's just a shorthand for calling
toInt()
or
toLong()
as needed.
m
I can't seem to find the convert function, do you know why that would happen? Also, where can I read about
expect
and
actual
r
Sometimes you need to import convert manually.
import kotlinx.cinterop.convert
https://kotlinlang.org/api/latest/jvm/stdlib/kotlinx.cinterop/convert.html
m
how would I then include separate files for different OSes? I couldn't find any easy methods for includes/excludes in gradle on the configurations
r
You probably want to read up more on the multiplatform project structure. See here for example https://kotlinlang.org/docs/mpp-discover-project.html#source-sets
m
I already checked there but it didn't specify how to include/exclude files other than from cinterops I already tried to do it through gradle with
Copy code
kotlin
sourceSets {
    val nativeMain by getting {
        kotlin.apply {
            exclude("**/platform/*.kt")
            when {
                hostOs == "Mac OS X" -> include("**/platform/macos.kt")
                hostOs == "Linux" -> include("**/platform/linux.kt")
                isMingwX64 -> include("**/platform/windows.kt")
            }
        }
    }
}
but it didn't seem to work
gradle runReleaseExecutableNative
also doesn't do anything, yet doesn't compile with any errors even though there should be according to the IDE