Recently I found a C library that I want to use in my C++ project.
This code is configured with global variables and writes it’s output to memory pointed by static pointers.
When I execute my project I would like 2 instances of the C program to run: one with configuration A and one with configuration B. I can’t afford to run my program twice, so I think there are 2 options:
- Make a C++ wrapper: The problem here is that the wrapper-class should contain all global/static variables the C library has. Since the functions in the C library use those variables I will have to create very big argument-lists for those functions.
- Copy-paste the C library: Here I’ll have to adapt the name of every function and every variable inside the C library.
Which one is the fastest solution?
Are there other possibilities to run 2 instances of the same C source?
Thanks,
Max
C++ -Wrapper
You get away easier by pasting “the entire library” – only slightly modfied – into a class.
becomes
There are mostly declarative changes (such as “killing” static and extern declarations). You would need to hunt down static variables inside the methods, though, and turn them into members as well
Separate Namespaces
That is an ugly solution, but might be enough for you:
If you are lucky, the optimizer/linker succeeds in folding the identical code. However, types in
A::andB::are unrelated.