The fact that you’re getting an error that includes OpaquePointer suggests that this is happening to you as well.
So, is GLFWmonitor an incomplete struct?
Share and Enjoy
Quinn “The Eskimo!” @ DTS @ Apple
[1] Incomplete structs are an oddity in C where you can declare a type like this:
struct Foo;
This says “there is a struct Foo but we don’t know anything about its contents yet”. This is commonly used for opaque ‘handles’ to objects. The C API is built in terms of pointers to such structs, allowing the implementer to keep all the details private.
You are saying the same thing. Where you say "opaque type", @eskimo says "incomplete struct", but you both mean the same thing: a C structure whose name you know but whose size you do not.
In this case, the public header files for GLFW seem not to include a definition for struct GLFWmonitor, which means that by definition it is incomplete or opaque. The type exists, but you don't know anything about its size. In Swift, pointers to such a type are aways OpaquePointer (see Opaque Pointers in Swift for a discussion of the pros and cons of this).
I don't know why CLion is getting this wrong, but wherever it is getting the type definitions from it has access to the actual structure definition and so is concluding the wrong thing about the type. The variable monitors therefore has the type UnsafeMutablePointer<OpaquePointer?>!, as @eskimo has noted.
Answering this more specifically: no, they cannot be. structs have size, they have layout, they can be copied around. Opaque types have no known size, no known layout, they cannot be held.
typealias Monitor = OpaquePointer // using this instead of GLFWmonitor because otherwise I get
// > error: use of undeclared type 'GLFWmonitor'
var monitors: [Monitor] {
var count: Int32 = 0
let monitors = glfwGetMonitors(&count)!
var res: [Monitor] = []
for i in 0..<Int(count) {
res += monitors[i]! as Monitor
}
return res
}