Passing array to a function (and why it does not work in C++)

后端 未结 7 1448
死守一世寂寞
死守一世寂寞 2020-12-15 15:03

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         


        
7条回答
  •  孤城傲影
    2020-12-15 15:56

    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

提交回复
热议问题