I have come across some C code that compiles, but I do not understand why. Specifically, I have a C library that has a lot of code using this format:
void ge
regarding the second part of your question:
Why doesn't the same version work in C++? When I literally change the file extension from .c to .cpp and try to recompile, I get
The source of that problem is that C++ mangles names.
To avoid name mangling when running C++ and trying to access a C library.
near the top of the header file for the C library, after the multiple inclusion guard insert:
#ifdef __cplusplus
extern "C" {
#endif
and near the end of the header file, before the #endif of the multiple inclusion guard, insert:
#ifdef __cplusplus
}
#endif
That will eliminate the problem of functions in the assocated library file not being found