C macro definitions in Cgo

。_饼干妹妹 提交于 2019-12-23 15:59:15

问题


I want to use existing macro values from C code in go. Using import "C" pseudo package we can import enums defined in C. Is there a way to import C macros?

package main

/*
enum levels {
    low1,
    medium,
    high
};
#define CMA 30
typedef enum {
    LOW = 0,
    MEDIUM = 1,
    HIGH = 2
} security;

*/
import "C"
import "fmt"

func main() {

    cc := new(C.enum_levels)
    //cm := new(C._*someliteral*_CMA)
    fmt.Println(*cc)

    fmt.Println(C.MEDIUM)

}

来源:https://stackoverflow.com/questions/44241836/c-macro-definitions-in-cgo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!