C macro definitions in Cgo

Viewed 2240

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)

}
0 Answers
Related