Why does CPointer<T>.pointed not work


Hi there,
I’m playing around with SDL and am currently stuck.

package main

import kotlinx.cinterop.CPointer
import sdl.*

fun main(args: Array<String>) {
  val window = SDL_CreateWindow("test", 10, 10, 800, 600, SDL_WINDOW_OPENGL)
  val surface: CPointer<SDL_Surface>? = SDL_GetWindowSurface(window)
  if (surface != null) {
    //                       the error is there  -v
    SDL_FillRect(surface, null, SDL_MapRGB(surface.pointed.format, 255, 255, 255))

the compiler always quits with “unresolved reference: pointed” and I don’t understand why.

In the docs there is

val <T : CPointed> CPointer<T>.pointed : T

and SDL_Surface is a subtype of CPointed.
What am I missing?


You probably need to import the extension property. Something like

import kotlinx.cinterop.*


import kotlinx.cinterop.pointed

should probably work (untested)


Yeah that was it. I didn’t know that extensions had to be explicitly imported. The linter complains about wildcard imports so I avoid them… Well now it works, so thank you!


There is a setting about that in intellij. You can set it to either use no wildcards, always use them or have more then x number of imports from the same package. You can also specify packages which are imported using wildcards only.