为什么我看到扔在一个C库? [英] Why do I see THROW in a C library?

查看:131
本文介绍了为什么我看到扔在一个C库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我这样做:
少/usr/include/stdio.h (这是只有一个C库 - 无关C ++)

When I do: less /usr/include/stdio.h (which is only a C library - nothing to do with C++)

我看 __ THROW 之后,相当多的函数声明。
另外,以上几个功能评论说,这是一个功能可能取消点,因此没有打上 __ THROW
这是怎么一回事呢?

I see __THROW after quite a few function declarations. Also, comments above a few functions say that 'This function is a possible cancellation point and therefore not marked with __THROW' What is all this for?

罚球,就是要对异常处理......但据我所知,C不会为其提供任何支持。

throw is meant to be for exception handling...but as far as I know, C doesn't provide any support for it.

请解释一下。

推荐答案

这头可能是C和C ++编译器该供应商之间共享。你是什​​么 __ THROW 定义为?

This header is likely shared between the C and C++ compiler for that vendor. Did you look what __THROW is defined as?

我怀疑一个类似于:

#ifdef __cplusplus
    #define __THROW throw()
#else
    #define __THROW
#endif

或者实际规格:

#ifdef __cplusplus
    #define __THROW(x) throw(x)
#else
    #define __THROW(x)
#endif

正如你所看到的,在C版本,它什么也不扩展。在C ++中,它确实你所期望的。这使得供应商重复使用相同的文件。

As you can see, in a C build, it expands to nothing. In C++, it does what you expect. This allows vendors to reuse the same file.

只是鸡蛋里挑骨头,这是不完全正确的:(这是唯一的C库 - 无关C ++)

Just to nitpick, this isn't entirely true: "(which is only a C library - nothing to do with C++)"

C ++标准库,包括使用C标准库的能力。实际的标头是<&CXXX GT; ,其中 XXX 是C头名。也就是说,包括C头<文件stdlib.h> 在C ++中,你做的< cstdlib> 。所以它确实有与C ++做。 :)

The C++ standard library includes the ability to use the C standard library. The actual header is <cxxx> where xxx is the C header name. That is, to include the C header <stdlib.h> in C++, you do <cstdlib>. So it does have to do with C++. :)

这就是为什么你看到code你怎么做。复制两种不同语言的标题将是维护和清洁的噩梦。

This is why you see the code you do. Duplicating the header for two different languages would be a nightmare for maintenance and cleanliness.

这篇关于为什么我看到扔在一个C库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆