scue / gitalk-comments

0 stars 0 forks source link

CGO类型及常见类型转换 | Linkscue's blogs #91

Open scue opened 6 years ago

scue commented 6 years ago

https://linkscue.com/2018/11/12/2018-11-12-cgo-types-covertion/#%E6%9B%B4%E5%A4%9A

关于Cgo的相关类型描述,官网上有这么一段话: The standard C numeric types are available under the names C.char, C.schar (signed char), C.uchar (unsigned char), C.short, C.ushort (unsigned short), C.int, C.uint (unsigned i

scue commented 6 years ago

一段调用示例:

// 生成公私钥
// int keypair(unsigned char* pubkey, unsigned char* prikey);
func Keypair() (pubKey, priKey []byte, e error) {
    pubKey = make([]byte, 48)
    priKey = make([]byte, 24)
    pPubKey := (*C.uchar)(unsafe.Pointer(&pubKey[0]))
    pPriKey := (*C.uchar)(unsafe.Pointer(&priKey[0]))

    rv := C.keypair(pPubKey, pPriKey)
    if rv != 0 {
        e = fmt.Errorf("keypair return %v", rv)
    }
    return
}