Skip to content

convert tips

sivchari edited this page May 1, 2021 · 3 revisions

convert tips

boolean, integer

The bool and numeric types are the same in Go, C, and Nim, so no conversion is needed.

string

When interacting in memory space

If the string type is created on the Go side, it will be returned as *C.char, and if it is created on the Nim side, the Go side can return it as string type.

If you want to use a string directly

Convert *C.char in C package C.GoString

func charTostring(a *C.char) {
    aa := C.GoString(a)
}

types

Proprietary types return pointers and restore them in the getter

Type      = TypeName | TypeLit | "(" Type ")" .
TypeName  = identifier | QualifiedIdent .
TypeLit   = ArrayType | StructType | PointerType | FunctionType | InterfaceType |
	    SliceType | MapType | ChannelType .
Clone this wiki locally