为什么我们没有多个编译器来检查“兼容"呢?和? [英] Why don't we have multiple compilers to check "compatible" with?

查看:38
本文介绍了为什么我们没有多个编译器来检查“兼容"呢?和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您知道 C# 现已发布到 7.1,具有许多新的语法和功能(称为Syntax Sugers").

但是这些糖在以前的版本如VS2013、VS2012或VS2010中是不能被吃掉的.如果你复制源代码并将它们放在那里,显然肯定会有很多错误,因为那里的编译器无法识别它们.不同的 VS 可能有不同种类的编译器.

如果我们想让我们的代码与不同类型 VS 中的不同编译器兼容",为什么我们没有多个编译器供我们切换(例如:如果我想编写适合 VS2010 的纯代码.我首先将我的编译器切换到 VS2010 的编译器并进行编写).那会更好吗?

解决方案

原始问题

<块引用>

使用具有较低网络框架和编译器的高级语法在最新的VS中,可以编译成功,为什么?

Matt Warren 的博客条目是关于这个问题的阅读很棒,埃里克·利珀特的.

<块引用>

一路上的一个常见技术是让编译器从高级语言特征到低级语言的低级"相同语言的功能.

简而言之,较新的"功能被转换(降低")为较旧的"功能 - 因此它们继续在框架上运行(即使它没有新功能的概念).

using 是一个降低的例子(它把 using 转换成 try finally):

////<摘要>///将 using 语句重写为 try finally 语句.有两种形式:///1) 使用 (expr) stmt///2) 使用 (C c = expr) stmt//////前者由 RewriteExpressionUsingStatement 处理,后者由///RewriteDeclarationUsingStatement(在循环中调用,为每个本地声明调用一次).///</总结>

奖励问题

<块引用>

如果我们想制作,为什么没有多个编译器供我们切换我们的代码与不同类型的不同编译器兼容"VS(例如:如果我想编写适合 VS2010 的简单代码.我首先将我的编译器切换到 VS2010 的编译器并进行编写).那变得更好?

只要您使用的是 VS 2013 或更高版本,您就可以轻松做到这一点.从 VS 2013 开始,C# 编译器可独立使用.

此外,您通常不需要这样做,因为 Visual Studio 允许您指定编译器版本.

You know that C# now comes to 7.1, with a lot of new syntaxes and features (called "Syntax Sugers").

But these sugers CANNOT BE EATEN in the previous versions such as VS2013, VS2012 or VS2010. If you copy the source codes and put them there, obviously there must be lots of mistakes because compilers there cannot recognize them. Different VS may have different kinds of compilers.

Why don't we have multiple compilers for us to switch if we wanna make our codes "compatible" with different compilers in different kinds of VS (e.g: If I wanna write a plain of codes suitable for VS2010. I firstly switched my compiler to that of VS2010 and do writing). That'd be better?

解决方案

Original question

To use a high-levelled syntax with a lower net framework and compiler in the latest VS, it can compile successfully, why?

Matt Warren's blog entry is a great read on this issue, as is Eric Lippert's.

A common technique along the way though is to have the compiler "lower" from high-level language features to low-level language features in the same language.

In short, the 'newer' features are converted ('lowered') to 'older' features - so they continue to run on the framework (even though it has no notion of the newer feature).

The Roslyn source code for using is an example of lowering (where it converts using into try finally):

/// <summary>
/// Rewrite a using statement into a try finally statement.  Two forms are possible:
///   1) using (expr) stmt
///   2) using (C c = expr) stmt
///   
/// The former is handled by RewriteExpressionUsingStatement and the latter is handled by
/// RewriteDeclarationUsingStatement (called in a loop, once for each local declared).
/// </summary>

Bonus question

Why don't we have multiple compilers for us to switch if we wanna make our codes "compatible" with different compilers in different kinds of VS (e.g: If I wanna write a plain of codes suitable for VS2010. I firstly switched my compiler to that of VS2010 and do writing). That'd be better?

You can easily do this, as long as you are on VS 2013 or later. The C# compiler is available standalone from VS 2013 onwards.

Additionally, you don't generally need to do this, since Visual Studio allows you to specify the compiler version.

这篇关于为什么我们没有多个编译器来检查“兼容"呢?和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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