Suppose I have a C++ library lib.h that uses classes and templates. Suppose also that I have a custom C++ header myLink.h with the following:
#include "lib.h"
//call methods from lib.h that use templates and classes
// and return an integer based off of the information gained from calling functions lib.h
extern "C" int foo(int param1, const int param2);
Now suppose I am in a C file called test.c. Is it legal to call function foo() as follows?
//in test.c
int first = foo(5, 6);
Also, what is going on at the object code / linker phase of compilation?
Thanks!
Yes, it’s legal. Although you should read below to make sure this legal call will link.
The use of classes won’t interfere. C++ classes will be compiled to object code that the linker will understand.
Edit from Chris Dodd’s comment:
Your templates will also be created by virtue of
foocalling them.