ISO C++ 的示例代码无效 C++/CLI

发布于 2024-10-10 13:07:35 字数 309 浏览 1 评论 0原文

关于 C++/CLI 是否是 C++ 的超集,我在互联网上看到了相互矛盾的答案。

关于这个问题的接受答案声称“技术上不行”,但没有提供非 C++/CLI 代码的示例符合 ISO C++。关于这个问题的另一个答案引用了一本相反的书。

那么,您能否提供在 C++/CLI 上失败的准确答案以及示例代码,或者在这个问题上引用可信来源(例如 MSDN)?

今天有人提出这个话题,我想告诉自己,但我在其他地方没有找到任何明确的答案!

I've seen contradictory answers on the internet with regard to whether C++/CLI is a superset of C++ or not.

The accepted answer on this question claims that "technically no", but doesn't provide an examples of non-C++/CLI code that conforms to ISO C++. Another answer on that question cites a book that says the opposite.

So, can you please provide accurate answers with example code that fails on C++/CLI or cite a trusted source (MSDN for example) on this matter?

I had someone this topic come up today and thought I would like to inform myself, but I didn't find any clear answer elsewhere!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

习ぎ惯性依靠 2024-10-17 13:07:36

有效的 C++,无效的 C++/CLI:

int main()
{
    int gcnew = 42;
}

gcnewgenericnullptr 都是 C++/CLI 中的保留字;当然,nullptr 在 C++0x 中并不是真正的问题。 Herb Sutter 在博客中介绍了C++/CLI 关键字:底层< /a> 于 2003 年。

无论如何,当我在处理大型混合代码库(C++ 和 C++/CLI)时,我从未遇到过语法问题或类似这样的琐碎问题。 C++/CLI 的巨大问题(当然,在我看来)是本机代码和托管代码具有完全不同的资源管理范例,并且在编写混合代码时很容易忘记某些事情需要哪种范例。我修复了许多错误,这些错误是由于假设托管资源被确定性销毁或本机资源将被垃圾收集器清理而导致的。

Valid C++, invalid C++/CLI:

int main()
{
    int gcnew = 42;
}

gcnew, generic, and nullptr are all reserved words in C++/CLI; nullptr isn't really an issue in C++0x, of course. Herb Sutter blogged about C++/CLI keywords: Under the hood in 2003.

For what it's worth, when I was working on a large mixed codebase (both C++ and C++/CLI), I never ran into syntax issues or trivial issues like this. The giant issue with C++/CLI (in my opinion, of course) is that native code and managed code have completely different resource management paradigms, and it's really easy when writing mixed code to forget which paradigm you need for certain things. I fixed a lot of errors that were due either to an assumption that managed resources were destroyed deterministically or that native resources would be cleaned up by the garbage collector.

挽袖吟 2024-10-17 13:07:36

我想知道过多的超级集/扩展争论。 C++/CLI 是一种语言,旨在充当 ISO C++ 和 ISO CLI 之间的绑定。我衷心推荐阅读 C++/CLI 设计原理
在文件的一开始就清楚地说明了设计目标:

C++/CLI 的使命是提供直接
供 C++ 程序员使用
现有的 CLI 库并创建新的
性能很少或没有性能的
开销,以最小的量
额外的符号,并具有完整的 ISO C++
兼容性。

I am wondering about the plethora of the super-set/extension polemics. C++/CLI is a new language designed to act as a binding between ISO C++ and the ISO CLI. I heartily recommend to read the C++/CLI Design Rationale
which clearly states the design goals at the very beginning of the document:

C++/CLI’s mission is to provide direct
access for C++ programmers to use
existing CLI libraries and create new
ones, with little or no performance
overhead, with the minimum amount of
extra notation, and with full ISO C++
compatibility.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文