Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7544005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:34:26+00:00 2026-05-30T08:34:26+00:00

I have a program (written in C/C++) that behaves as a socket server. I’d

  • 0

I have a program (written in C/C++) that behaves as a socket server. I’d like to write the client in python. The packets exchanged over the TCP socket follow a “home-made” protocol (simple) using macros defined as #define… in a XXX.h file.
I’d like to parse the XXX.h file to generate a equivalent XXX.py
The XXX.h file only contains CPP macro definitions (and comments) e.g:

//the following commands are used when talking to the server
//A tcp message is: the command(32bit word) followed by the flags (32 bits)
#define CMD_DO_SOMETHING1  1  //this does something
#define CMD_DO_SOMETHING2  2  //that does something else
 #define FLAG1   0x0001        //These flags are used as parameter in cmd2
 #define FLAG2   0x0002
 #define FLAG3   0x0004
 #define FLAG4   0x0008
 #define TEST_FLAG1(x) (x&FLAG1) //this tests for flag1

I would like to get something like: XXX.py:

CMD_DO_SOMETHING1=1
CMD_DO_SOMETHING2=2
 FLAG1=1
 ...
 def test_flag1(x):
    return(x&flag1)

I have been briefly looking at swig, but was not convinced it really did what I am looking for. Parsing the XXX.h file manually and matching regular expression feels wrong. So does the idea of running CPP on my *.py file.
At least, the constant definition should be converted so I don’t have to rewrite them twice.
Any better ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:34:28+00:00Added an answer on May 30, 2026 at 8:34 am

    h2py.py does exactly that. It is included in the Python distribution(*) in Tools/scripts

    If you need to convert more than #defines, see the question Convert C++ Header Files To Python

    EDIT: (*) It is included at least in the full source distribution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a client program written in .NET 2.0, that connects to the web
I have a Perl program that I've written that parses SQL-like statements and creates
Exposition: I'm familiar with C/C++/Scheme & OpenGL. I have this client/server program written in
I have a program written in python that uploads an archive (zip file) to
I have a program written in python that uses dbus to detect inserted usb
I have a program written in python, and I would like to make it
I have a program written in c that gets invoked like: my_program arg1 arg2
I have a console program written in C# that I am using to send
I have a program written in VB.Net (Visual Studio 2008) that uses a DLL
I have written a program that will etablish a network connection with a remote

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.