Reliably converting C preprocessor macros to python code

Posted by manual-manuel on Stack Overflow See other posts from Stack Overflow or by manual-manuel
Published on 2010-04-16T15:47:59Z Indexed on 2010/04/17 12:23 UTC
Read the original article Hit count: 189

Filed under:
|
|

Hi,

I have a bunch of C macros the operation of which I need to simulate in python. I saw some pointers to pygccxml or ctypeslib etc. Are these the ways to go ? Or is there something out there that is better ?

The C macros if and when they change, I would like the python implementation to be auto generated rather than having to make manual modifications. Hence the question.

<my_c_header.h>

/* #defines type 1 */
#ifdef OS

#define NUM_FLAGS   (uint16_t)(3)
#define NUM_BITS    (uint16_t)(8)

#else

#define NUM_FLAGS   (uint16_t)(6)
#define NUM_BITS    (uint16_t)(16)
#endif

#define MAKE_SUB_FLAGS    (uint16_t)((1<<NUMFLAGS) -1)

#define MAKE_TOTAL_FLAGS(x)  (uint16_t)((x & MAKE_SUB_FLAGS) >> NUM_BITS)

/* #defines type 2 */

#ifdef OS
#DO_SOMETHING(X)  os_specifc_process(x)
#else
#DO_SOMETHING(x)  
#endif

/* #defines type 3 */

enum
{
CASE0,
CASE1,
CASE2
}

#define MY_CASE_0     ((uint16_t)CASE0)
#define MY_CASE_1     ((uint16_t)CASE1)
#define MY_CASE_2     ((uint16_t)CASE2)
#define

/*End of file <my_c_header.h> */

Thanks M

© Stack Overflow or respective owner

Related posts about python

Related posts about c