Using C Libraries for C++ Programs

后端 未结 7 2158
北海茫月
北海茫月 2020-11-27 14:50

I am trying to control Dynamixel servos using a GUI made using Qt. Dynamixel provides a C set of C libraries to control the motors, while the only way of making GUI\'s I kno

相关标签:
7条回答
  • 2020-11-27 15:19

    You can use C libraries from C++... however there are some caveats.

    One big thing to watch out when using third-party C libraries with C++ is error handling.

    Some C libraries use facilities like setjmp/longjmp for error handling. (lua is a notable example). This means that on error stack unwinding will not occur in the normal manner, and you may leak resources. Things like the usual C++ RAII style guards for resource protection fail dismally. (These calls are worse than goto for C++ code).

    Also exceptions can be a concern. If a C++ exception propagates to a C/C++ boundary then the application may terminate rather than propagating the exception. (Depending on how the C library was compiled and your OS etc.) (You might get this situation if you pass a C++ function into a C library as a callback.)

    0 讨论(0)
提交回复
热议问题