meekrosoft / fff

A testing micro framework for creating function test doubles
Other
768 stars 169 forks source link

When is it necessary to guard FFF macros with extern C? #88

Open thekenu opened 4 years ago

thekenu commented 4 years ago

I am using fff to mock inputs to these embedded C functions and using gtest (C++ framework) to run test suites. Naturally, the embedded C code must be imported into gtest files using extern C. Is it ALSO necessary to guard things like DECLARE_FAKE_VOID_FUNC with extern C in this case? The project seems to compile either way so I'm curious if there's a best practice.

leonardopsantos commented 1 year ago

the embedded C code must be imported into gtest files using extern C

You mean you have to add extern "C" guards around C header files?

extern "C"
{
#include <some_c_header.h>
}

Is it ALSO necessary to guard things like DECLARE_FAKE_VOID_FUNC with extern C in this case

I don't know which linker you're using, but with the GNU linker, unless I wrap the fakes like so:

extern "C"
{
FAKE_VALUE_FUNC(uint8_t , some_function, uint8_t);
}

I get a linker error because of name mangling.