0

Building on an answer from this question.

/* interface.h */

struct library {
    const int some_value;
    void (*method1)(void);
    void (*method2)(int);
    /* ... */
};

extern const struct library Library;
/* interface.h */

/* interface.c */
#include "interface.h"

void method1(void)
{
   ...
}
void method2(int arg)
{
   ...
}

const struct library Library = {
    .method1 = method1,
    .method2 = method2,
    .some_value = 36
};
/* end interface.c */

/* client code */
#include "interface.h"

int main(void)
{
    Library.method1();
    Library.method2(5);
    printf("%d\n", Library.some_value);
    return 0;
}
/* end */

How can I put a wrapper around Library?

Wrapper.h

struct Wrapper {
   const Library
};

extern const struct wrapper Wrapper;

Wrapper.c

const struct wrapper Wrapper = {
    .Library = Library
};

and then access like wrapper.Library.method1();

AppDeveloper
  • 1,488
  • 5
  • 18
  • 39

0 Answers0