问题描述
如果您有c代码,例如png lib,使用您自己的io处理程序,用c ++编写,并且由于某些io错误而抛出异常。让它通过c代码并将其捕获在c代码之外吗?我知道要注意内存泄漏,但通常所有的结构都可以预先分配。
完全取决于编译器如果这将工作与否。没有一个语言标准可以明确地说明其他语言应该做什么。
在最好的情况下,异常将通过C代码并返回到下一个C ++级别,同时可能泄漏任何动态分配的C结构。在不太好的情况下,它将崩溃并烧录!
当然可以将C代码编译为C ++,同时也检查它是否为异常中立。 / p>
If you have c code, for example the png lib, with your own io handlers which are written in c++ and an exception gets thrown due to some io error. is it ok to let it go through the c code and catch it outside of the c code? i know that care has to be taken with memory leaks but typically all structures get pre-allocated.
It is entirely up to the compiler if this will work or not. None of the language standards can obviously say anything about what the other language should do.
In the best case, the exception will pass the C code and get back to the next C++ level while possibly leaking any dynamically allocated C structures. In the less good case, it will crash and burn!
One possibilty is of course to compile the C code as C++, while also checking that it is exception neutral.
这篇关于如果异常被抛出“通过”,会发生什么c代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!