[Y-devel] C API?

Maurice van der Pot griffon26 at kfk4ever.com
Sun Feb 22 10:40:30 GMT 2004


On Sat, Feb 21, 2004 at 11:46:17PM +0000, Richard Hills wrote:
>         This is something I'd be happy to do. I was wondering, is it possible
> for a C interface to use the underlying C++ interface, in order to
> reduce code duplication? As far as I understand it, the C interface for
> GTK is the base for several other language wrappers, so is it possible
> to do the same thing in reverse? Thanks,

To write a C interface for C++ functions, the glue has to be written in C++.
Say you want to export a C interface called cfunction() for a C++ function
called cplusplusfunction().

You'd make a file cinterface.h containing:

  #ifdef __cplusplus
  extern "C" {
  #endif

  int cfunction(int i);

  #ifdef __cplusplus
  }
  #endif

and a file cinterface.cpp containing:

  #include "cinterface.h"
  #include "cplusplusinterface.h"

  int cfunction(int i)
  {
    return cplusplusfunction(i);
  }

Of course if classes and objects are involved, it's a bit trickier.
But that isn't what you are trying to do, is it?

Best regards,
Maurice.




More information about the Y-devel mailing list









2026 © www.Y-Windows.Org - All Rights Reserved