I have some consts or defines that I'm using in both a C program and a Python program however I have defined them separately in both files. It would be nice to have a single .h file that I could use for both the C and Python program 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 a lot of constant values to define which I will need access to from both a C program and a Python program so I was wondering if there's a good way of implementing this.
#includethat is used to paste in a bunch of text in the source code. And the syntax for "constant defines" is not the same between the two languages. Since Python doesn't use a preprocessor, you can't use that to cut out the C parts of the code. Please clarify.