Using a common header file for Python & C

I have some constants or it determines that I use both the C program and the Python program, however I defined them separately in both files. It would be nice to have one .h file that I could use for C and Python programs to avoid having to make changes in two places.

u16 get_opt(int arg) {
    u16 mode;
    if(arg == 1) {
        mode = 0xabc1;
    } else if (arg == 2) {
        mode = 0xf104;
    } else if(arg == 3) {
        mode = 0xff16;
    }
    return mode;
}

In python, I also have

MAPPING = {
    1: 0xabc1,
    2: 0xf104,
    3: 0xff16
}

def get_opt(arg) {
    return MAPPING[arg]
}

I have many constant values ​​to determine which access I need from both the C program and the Python program, so I was wondering if there is a good way to implement it.

+4
source share
1 answer

, , , SWIG (. : http://www.swig.org/tutorial.html).

, , swig .

+3

Source: https://habr.com/ru/post/1583918/


All Articles