问题描述
您好,再次原谅我
我从英特尔阅读检测的多处理器拓扑在IA-32架构。我被重新编码的例子。不过,我读了code本句__try和__except。
I am reading "Detecting Multiprocessor Topology in IA-32 Architecture" from Intel. I was recoding the example. However I read this sentences __try and __except in the code.
我发现MSDN Microsoft网页的一些信息,但是我用gcc编译器/连接
I found MSDN Microsoft web page some information but I am using gcc compiler/linker
在GCC __try和__except有效的句子?
是__try和__except便携式句子在*马钱的环境?
确实存在比__try和__except语句异常处理一个更好的模式,用C?
are __try and __except valid sentences in gcc?are __try and __except portable sentences on *nux environments?do exist a better mode than __try and __except sentences for exception handling in C?
在此先感谢。
推荐答案
根据, __试
和 __除了
是扩展C语言。因此,它们是不可移植的开箱即用的。
General considerations
According to MSDN, __try
and __except
are extensions to the C language. As such, they are not portable out of the box.
对于某些应用程序有可能模仿他们的行为使用宏和的setjmp
/ 的longjmp
结构。一般来说,这将不会是这样。特别是,MSDN指出
For some applications it might be possible to mimic their behaviour using macros and a setjmp
/longjmp
constructs. In general this will not be the case. In particular, MSDN states that
的 __除了
前pression的范围执行 __试
的身体。
不能单独使用宏来实现。
which cannot be achieved using macros alone.
是 __试
和 __除了
在GCC有效的句子?
没有,他们没有,因为GCC不支持C的这种微软的方言。
No, they are not, as gcc does not support this Microsoft dialect of C.
是__try和__except便携式句子在*马钱的环境?
没有,他们没有,虽然有一些方法来实现类似的异常处理在* nix为好。
No, they are not, although there are ways to achieve similar exception handling on *nix as well.
确实存在比__try和__except语句异常处理一个更好的模式,用C?
有一个强有力的理由来使用C ++,当你做异常处理。 C ++范围与析构函数对象是比例外标准C资源管理的presence更健壮。因此,尽管它们提供的实现尝试
和抓
对于C这种或那种方式,我建议对他们和赞成C ++来代替。在C ++异常处理是标准的一部分,因此,所有符合标准的编译器的支持,没有可移植性问题。
There is a strong reason to use C++ when you do exception handling. C++ scoped objects with destructors are much more robust in the presence of exceptions than standard C resource management. So while there are implementations which provide try
and catch
for C one way or another, I'd advise against them and favor C++ instead. Exception handling in C++ is part of the standard and therefore supported by all standards-compliant compilers, without portability issues.
这篇关于__try和__exception便携的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!