Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why does the compiler generate undefined symbols for functions taking pointer to functions?

0
Posted

Why does the compiler generate undefined symbols for functions taking pointer to functions?

0

The linkage of the function that is pointed to is now part of the function type. From Standard §7.5; Stroustrup §9.2.5: In a linkage specification, the specified language linkage applies to the function types of all function declarators, function names, and variable names introduced by the declaration. For example: extern “C” void f1(void (*pf)(int)); // the name f1 and its function type have C linkage; // pf is a pointer to a C function In the following example, the argument errFunc has C linkage in the declaration but has C++ linkage in the definition in func.cpp. As a result, the declaration and definition do not match. // func.h extern “C” { void Test_OK(char *msg); typedef void (*fp)(char*); void Test_Not_OK(fp); } // func.cpp #include void Test_Not_OK(fp errFunc) { errFunc(“Test not OK”); } S: Create a typedef with either C or C++ linkage and use it as the argument type.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123