• cgo


    Go references to C
    1、Memory allocations made by C code are not known to Go's memory manager. When you create a C string with C.CString (or any C memory allocation) you must remember to free the memory when you're done with it by calling C.free.

    2 、To access a struct, union, or enum type directly, prefix it with struct_, union_, or enum_, as in C.struct_stat.

    3、The size of any C type T is available as C.sizeof_T, as in C.sizeof_struct_stat.

    4、_, err := C.voidFunc()  C errno variable as an error (use _ to skip the result value if the function returns void).

    C references to Go 
    1、go函数导出,单个返回值与多返回值。found in the _cgo_export.h generated header, after any preambles copied from the cgo input files. Functions with multiple return values are mapped to functions returning a struct.
    //export MyFunctionf
    func MyFunction(arg1, arg2 int, arg3 string) int64 {...}


    //export MyFunction2f
    func MyFunction2(arg1, arg2 int, arg3 string) (int64, *C.char) {...}
    they will be available in the C code as:
    extern int64 MyFunction(int arg1, int arg2, GoString arg3);

    extern struct MyFunction2_return MyFunction2(int arg1, int arg2, GoString arg3);

    2 、Go code may not store a Go pointer in C memory. C code may store Go pointers in C memory, subject to the rule above: it must stop storing the Go pointer when the C function returns.

      

  • 相关阅读:
    以CCF CSP认证为抓手,积极探索软件基础能力递进式培养体系
    HDU1878 欧拉回路
    HDU1878 欧拉回路
    Java---casting(对象转型)
    Java---package和import语句
    Java---方法的重写
    Java---继承中的构造方法
    Java---内存分析
    Java---多个类写在一个类文件中
    Java---SSH框架认识
  • 原文地址:https://www.cnblogs.com/xiaomayi-cyj/p/10348279.html
Copyright © 2020-2023  润新知