Why does the compiler generate undefined symbols for functions taking pointer to functions?
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
Related Questions
- Why must classes reside in headers for automatic template instantiation? Q: Why does the compiler generate undefined template symbols?
- Why are some ANSI/ISO Standard library functions showing up as undefined, even though Ive got an ANSI compiler?
- Why does the compiler generate undefined symbols for functions taking pointer to functions?