C++0x 遗留代码问题

发布于 2024-09-30 11:34:00 字数 357 浏览 0 评论 0原文

众所周知,由于遗留代码,C++0x 无法带来很多重要的变化:所有遗留代码(包括 C 代码)都可以使用 C++0x 编译器进行编译。

那么为什么不添加类似 #pragma syntax(language_version) 这样的内容,它将允许新语法进行重大更改呢?

#include <legacy_code_header.h>

#pragma syntax(2098)

// something strange
func(x)
{
   return x + 1, x * 2;
}

int main()
{
   a, b = func(1.0);
   return a + b;
}

As all you know, C++0x can't bring lots of important changes because of legacy code: all legacy code (including C code) can be compilable with a C++0x compiler.

So why don't add something like #pragma syntax(language_version), which will allow new syntax with breaking changes?

#include <legacy_code_header.h>

#pragma syntax(2098)

// something strange
func(x)
{
   return x + 1, x * 2;
}

int main()
{
   a, b = func(1.0);
   return a + b;
}

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

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

发布评论

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

评论(1

梦初启 2024-10-07 11:34:00

某些 C++0x 编译器可能允许这样做。毕竟,#pragmas 通常是特定于编译器的,而不是由标准规定的。其他人通过命令行选项支持这一点。

Some C++0x compilers might allow this. After all, #pragmas are generally compiler specific and not dictated by the standard. Others support this with command line options.

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