By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 884 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

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

P: n/a
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


void f();

will produce this C header :

// C interface

#ifdef __cplusplus
extern "C" {

// 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
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)

Apr 19 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a
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!

Apr 19 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.