Is there a performance degradation / penalty in using pure C library in C++ code?

前端 未结 3 1572
伪装坚强ぢ
伪装坚强ぢ 2020-12-31 03:52

I saw this link but I\'m not asking for a performance degradation for code using \"extern\". I mean without \"extern\", is there \"context switching\" when using C library i

3条回答
  •  轮回少年
    2020-12-31 04:32

    C++ has grown and changed a lot since its inception, but by design it is backwards-compatible with C. C++ compilers are generally built from C compilers, but even more modernized with link-time optimizations. I would imagine lots of software can reliably mix C and C++ code, both in the user spaces and in the libraries used. I answered a question recently that involved passing a C++ class member function pointer, to a C-implemented library function. The poster said it worked for him. So it's possible C++ is more compatible with C than any programmers or users would think.

    However, C++ works in many different paradigms that C does not, as it is object-oriented, and implements a whole spectrum of abstractions, new data types, and operators. Certain data types are easily translatable (char * C string to a std::string), while others are not. This section on GNU.org about C++ compiler options may be of some interest.

    I would not be too worried or concerned about any decline in performance, when mixing the two languages. The end user, and even the programmer, would hardly notice any measurable changes in performance, unless they were dealing with big abstractions of data.

提交回复
热议问题