什么是C ++中的模块? [英] What is a module in C++?

查看:186
本文介绍了什么是C ++中的模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


这是




我已经使用了C ++ cs.htm现在阅读这本书,所以我想引用章节总结,我认为添加了一些清晰:


不要把石头你的邻居的花园:没有无处不在的二进制标准的C ++异常处理。不要允许异常在两段代码之间传播,除非您控制用于构建两端的编译器和编译器选项;否则,模块可能不支持异常传播的兼容实现。通常,这可以归结为:不要让异常在模块/子系统边界之间传播。



解决方案

这是一个好问题。 C ++标准不使用单词
模块(我不认为,至少),通常的日常含义
是一个翻译单元。除了那不能是
Herb和Andrei的意思,因为使用
异常的真正目的是向上传播出
代码&mdash的本地主体;否则,你会使用返回码。



我只能猜测,但它们可能意味着可能合法地在不同的DLL中实现
的东西。如果
DLL已经使用不同的编译器编译,或者使用
不同的语言,则传播
跨DLL边界的异常可能是一个问题。否则...



通常认为最好的做法是在main中有一个try / catch
块(或者在其他高级函数中, b $ b thread),并捕获所有异常,无论它们来自哪里
。当你这样做时,现代编译器没有问题。


What does the term module refer to in the following sentence?

Don't allow exceptions to propagate across module boundaries.

This is rule 62 in C++ Coding Standards by Herb Sutter and Andrei Alexandrescu.


I have now read the book, so I would like to quote the section summary, which I think adds some clarity:

Don't throw stones into your neighbor’s garden: There is no ubiquitous binary standard for C++ exception handling. Don't allow exceptions to propagate between two pieces of code unless you control the compiler and compiler options used to build both sides; otherwise, the modules might not support compatible implementations for exception propagation. Typically, this boils down to: Don’t let exceptions propagate across module/subsystem boundaries.

解决方案

That's a good question. The C++ standard doesn't use the word module (I don't think, at least), and the usual everyday meaning is something like a translation unit. Except that that can't be what Herb and Andrei mean, since the real purpose of using exceptions is to propagate up out of the local body of code—otherwise, you'd use return codes.

I can only guess, but they probably mean something that might reasonably be implemented in a different DLL. Propagating exceptions accross DLL boundaries might be a problem, if the DLL's have been compiled with a different compiler, or use a different language. Otherwise...

It's usually considered best practice to have a single try/catch block in main (or in some other high level function, in each thread), and catch all exceptions there, regardless of where they come from. And there are no problems with modern compilers when you do this.

这篇关于什么是C ++中的模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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