3

I am writing a dll which supports interfacing with both C and C++ language applications. The dll itself is written in C++, so the question is can i use Catch2 framework for unittesting both C and C++ applications ?

What are the things i need to look out for ? and are there any alternatives which anyone can suggest ?

1 Answers1

6

The tests have to be written in C++.

To test a function, you simply need to be able to call it. So, thus the question is equivalent to "Can C functions be called from C++?".

In most cases, the answer is yes. There is a "language linkage" feature just for this purpose. There are some exceptions where C is incompatible, such as functions whose name is a C++ keyword like delete. To call such function, you would need to write a wrapper function in C, with a compatible name and call that wrapper from the test written in C++.

eerorika
  • 232,697
  • 12
  • 197
  • 326