`
talin2010
  • 浏览: 520715 次
  • 性别: Icon_minigender_1
  • 来自: 河北
社区版块
存档分类
最新评论

15.1 End points and reachability

F# 
阅读更多
Every statement has an end point. In intuitive terms, the end point of a
statement is the location that
immediately follows the statement. The execution rules for composite
statements (statements that contain
embedded statements) specify the action that is taken when control reaches
the end point of an embedded
statement. [Example: For example, when control reaches the end point of a
statement in a block, control is
transferred to the next statement in the block. end example]
If a statement can possibly be reached by execution, the statement is said
to be reachable. Conversely, if
there is no possibility that a statement will be executed, the statement is
said to be unreachable.
[Example: In the example
void F() {
Console.WriteLine("reachable");
goto Label;
Console.WriteLine("unreachable");
Label:
Console.WriteLine("reachable");
}
C# LANGUAGE SPECIFICATION
178
the second invocation of Console.WriteLine is unreachable because there is
no possibility that the
statement will be executed. end example]
A warning is reported if the compiler determines that a statement is
unreachable. It is specifically not an
error for a statement to be unreachable.
[Note: To determine whether a particular statement or end point is
reachable, the compiler performs flow
analysis according to the reachability rules defined for each statement.
The flow analysis takes into account
the values of constant expressions (§14.15) that control the behavior of
statements, but the possible values of
non-constant expressions are not considered. In other words, for purposes
of control flow analysis, a nonconstant
expression of a given type is considered to have any possible value of that
type.
In the example
void F() {
const int i = 1;
if (i == 2) Console.WriteLine("unreachable");
}
the boolean expression of the if statement is a constant expression because
both operands of the
== operator are constants. As the constant expression is evaluated at
compile-time, producing the value
false, the Console.WriteLine invocation is considered unreachable. However,
if i is changed to be a
local variable
void F() {
int i = 1;
if (i == 2) Console.WriteLine("reachable");
}
the Console.WriteLine invocation is considered reachable, even though, in
reality, it will never be
executed. end note]
The block of a function member is always considered reachable. By
successively evaluating the reachability
rules of each statement in a block, the reachability of any given statement
can be determined.
[Example: In the example
void F(int x) {
Console.WriteLine("start");
if (x < 0) Console.WriteLine("negative");
}
the reachability of the second Console.WriteLine is determined as follows:
? The first Console.WriteLine expression statement is reachable because the
block of the F method is
reachable (§15.2).
? The end point of the first Console.WriteLine expression statement is
reachable15.2 because that
statement is reachable (§15.6 and §15.2).
? The if statement is reachable because the end point of the first
Console.WriteLine expression
statement is reachable (§15.6 and §15.2).
? The second Console.WriteLine expression statement is reachable because
the boolean expression of
the if statement does not have the constant value false.
end example]
There are two situations in which it is a compile-time error for the end
point of a statement to be reachable:
? Because the switch statement does not permit a switch section to ?fall
through? to the next switch
section, it is a compile-time error for the end point of the statement list
of a switch section to be
reachable. If this error occurs, it is typically an indication that a break
statement is missing.
? It is a compile-time error for the end point of the block of a function
member that computes a value to be
reachable. If this error occurs, it typically is an indication that a
return statement is missing.
分享到:
评论

相关推荐

    Reachability

    Reachability是iOS、macOS和Xamarin开发中的一个重要概念,用于检测设备的网络连接状态,例如是否连接到互联网,以及连接的类型(如Wi-Fi、蜂窝数据等)。在iOS和macOS应用开发中,良好的网络连接性检测是提供稳定...

    ios Reachability

    Reachability是苹果官方提供的一款用于检测iOS设备网络状态的示例代码库,它极大地简化了开发者在应用中检查网络连通性的过程。这个DEMO包含了详细的实现方式和使用示例,帮助开发者理解如何在自己的应用中集成网络...

    Reachability 网络判断库文件

    Reachability 是一个在iOS和macOS开发中广泛使用的开源库,由Tony Million 创建,用于检测设备的网络连通状态和网络类型。这个库基于Apple的SystemConfiguration框架,它提供了简单易用的接口来帮助开发者判断应用...

    Reachability使用说明<转载>

    Reachability是iOS开发中一个非常重要的工具,它用于检测设备的网络可达性,例如Wi-Fi、蜂窝数据等网络状态的变化。这个工具是由斯坦福大学的Scotty Loveless开发的,并且在iOS开发者社区中广泛使用。这篇博客文章...

    IOS ReachAbility

    IOS 网络编程 ReachAbility头文件和源文件,用于判定网络的连接情况

    Reachability 网络状态的使用和封装,更加方便使用

    Reachability 是 iOS 开发中一个重要的工具类,用于检测设备的网络状态,包括无网络、WiFi、蜂窝数据等。这个工具最初由 Tony Million 设计并实现,现在已经被广泛使用在许多 iOS 应用中。在本文中,我们将深入探讨 ...

    iOS中使用 Reachability 检测网络

    Reachability是Apple提供的一款工具,用于检测设备的网络可达性,即是否可以连接到互联网。这篇博客文章将深入探讨如何在iOS项目中使用Reachability来监控网络状态,并提供相关的源码分析。 一、 Reachability简介 ...

    Reachability网络状态

    Reachability是iOS开发中用于检测网络连接状态的一个重要工具,由Tony Million开发并维护,它提供了简单的方法来判断设备当前的网络连通性。在iOS 11及更高版本中,由于苹果对用户隐私的加强保护,不再推荐使用Key-...

    FERRARI - Flexible and Efficient Reachability Range Assignment for Graph Indexing-计算机科学

    FERRARI: Flexible and Efficient Reachability Range Assignment for Graph IndexingStephan Seufert1, Avishek Anand1, Srikanta Bedathur2, Gerhard Weikum11Max Planck Institute for Informatics, Germany {...

    iOS_Reachability

    Reachability 是 iOS 开发中一个重要的知识点,用于检测设备当前的网络状态,包括是否连接到互联网,以及连接的类型(例如蜂窝数据还是 Wi-Fi)。这个例子是苹果官方提供的,对于开发者来说,是一个非常有价值的参考...

    Reachability.swift:使用 Swift 闭包实现的网络状态检查库,可以取代 Apple 的 Reachability 库.zip

    Reachability.swift:使用 Swift 闭包实现的网络状态检查库,可以取代 Apple 的 Reachability 库.zip,Replacement for Apple's Reachability re-written in Swift with closures

    Reachability.zip

    Reachability是iOS开发中一个非常重要的概念,它用于检测设备的网络可达性,即设备是否能够连接到互联网以及通过何种方式连接。这个功能在开发任何需要网络通信的应用时都至关重要,因为它可以帮助应用根据网络状态...

    iOS 网络检查 Reachability

    Reachability是Apple提供的一个库,用于检测设备当前的网络可达性,包括Wi-Fi、蜂窝数据以及互联网是否可达。这个库可以帮助开发者及时响应网络状态的变化,比如在网络断开时提示用户或者暂停网络依赖的操作。 首先...

Global site tag (gtag.js) - Google Analytics