Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

IDL interface in C

As in C++, IDL interfaces are mapped to C structs, but a function pointer is generated for each method instead of a method because C does not support classes. The generated C structure is designed to be compatible with the compiler-generated vtable for the C++ structure (see Broken Link); therefore, the C language mapping does not support multiple inheritance of interfaces.

Additionally, because types declared within an interface must be scoped within that interface, any such types are prepended with the name of the enclosing interface and an underscore, as is done with modules. If the interface is itself within a module, then any types within the interface will be prepended with the fully-qualified name of the interface – that is, the names of all enclosing modules, separated by underscores, along with the name of the interface. Any types defined within an interface will be extracted and defined before the corresponding structure in the mapping. For example:

interface IFoo
{
  struct inner
  {
   /* ... */
  };

  long process(in short a);
};

is mapped as:

/* Forward-declare IFoo if it is used in IFoo_inner */
struct IFoo;

typedef struct IFoo_inner
{
  /* ... */
} IFoo_inner;

typedef struct IFoo
{
  int (*process)(IFoo* self, short int a);
} IFoo;