Auto-generating C header file from C++ header?

Discussion in 'C++' started by Bit byte, Apr 19, 2006.

  1. Bit byte

    Bit byte Guest

    I am having to provide a C interface to (quite a few) C++ classes.
    Is there a way that I can automate this process?

    example :

    class X
    {
    public:

    X();

    void f();
    };

    will produce this C header :

    // C interface

    #ifdef __cplusplus
    extern "C" {
    #endif

    // Type-safe, opaque pointer.
    typedef struct C_X_* X_Handle;


    X_Handle CreateX();
    void DestroyX(X_Handle x);

    void X_f(X_Handle x);

    #ifdef __cplusplus
    }
    #endif


    I can then (manually) implement this:

    // C++ implementation

    X_Handle CreateX()
    {
    return reinterpret_cast<X_Handle>(new X);
    }

    void DestroyX(X_Handle x)
    {
    delete reinterpret_cast<X*>(x);
    }

    void X_f(X_Handle x)
    {
    reinterpret_cast<X*>(x)->f();
    }
     
    Bit byte, Apr 19, 2006
    #1
    1. Advertising

  2. Bit byte

    benben Guest

    Not that I know what can help you, but I'm just wondering how you would
    translate private function, template, virtual function etc...

    Seems to me a very complicated task :) Good luck!

    Regards,
    Ben
     
    benben, Apr 19, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?V2FyYW4=?=

    Auto-Suggested Textbox like google auto suggest

    =?Utf-8?B?V2FyYW4=?=, Apr 20, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    8,569
    inrakeshworld
    Jul 27, 2007
  2. linkswanted
    Replies:
    1
    Views:
    991
  3. mlt
    Replies:
    2
    Views:
    907
    Jean-Marc Bourguet
    Jan 31, 2009
  4. Christopher Calhoun

    Sorting when Auto-generating HyperLink Coloumnsm HELP!!!

    Christopher Calhoun, Jan 28, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    97
    Christopher Calhoun
    Jan 28, 2004
  5. Brett Ossman

    Auto-Generating Passwords That Require User to Change

    Brett Ossman, Feb 26, 2009, in forum: ASP .Net Security
    Replies:
    1
    Views:
    668
    Alexey Smirnov
    Mar 13, 2009
Loading...

Share This Page