C++ by-reference argument and C linkage

前端 未结 5 2141
执笔经年
执笔经年 2021-01-08 00:07

I have encountered a working (with XLC8 and MSFT9 compilers) piece of code, containing a C++ file with a function defined with C linkage and a reference argument. This bugs

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-08 00:36

    I think you already got some good answers so just pointing out something extra on your question.

    My humble understanding is that extern merely creates a C symbol.

    So your example still "seems to work" (gcc/g++) even when I add a class object - I had to try ir to believe it:

    class A {};
    
    extern "C" void f(int &i, A a) {
        i++;
    }
    

提交回复
热议问题