0

fileA.c has a static function (static int funcA())

The fileA.c can not be modified.

fileB.c How can I use the funcA()?

Anıl Aşık
  • 360
  • 1
  • 15
Cena
  • 1
  • 2

2 Answers2

1

In general you cannot, that's the entire point of static in this case.

Perhaps fileA.c has a way to get the address of the function, then you can use that to make a call, but you can't reference static symbols directly.

For test code, one "trick" that's often done is to #include the C file in the test file, so in fileA_test.c you'd have:

#include "fileA.c"

bool test_fileA_something(void)
{
  TEST_ASSERT(foo() == 42);
}

The above assumes that foo is a static function inside fileA.c, and this works since the files are compiled together.

unwind
  • 391,730
  • 64
  • 469
  • 606
0

Not. The compiler has every right to not include funcA in fileA.obj. And even if it is included, it might not be in a form that the linker can use. In fact, if included it must be in a way that doesn't clash with other functions names funcA

MSalters
  • 173,980
  • 10
  • 155
  • 350