Annex B Portability issues

This clause is informative.

B.1 General

This annex collects some information about portability that appears in this specification.

B.2 Undefined behavior

The behavior is undefined in the following circumstances:

  1. The behavior of the enclosing async function when an awaiter’s implementation of the interface methods INotifyCompletion.OnCompleted and ICriticalNotifyCompletion.UnsafeOnCompleted does not cause the resumption delegate to be invoked at most once (§12.9.8.4).
  2. Passing pointers as reference or output parameters (§23.3).
  3. When dereferencing the result of converting one pointer type to another and the resulting pointer is not correctly aligned for the pointed-to type. (§23.5.1).
  4. When the unary * operator is applied to a pointer containing an invalid value (§23.6.2).
  5. When a pointer is subscripted to access an out-of-bounds element (§23.6.4).
  6. Modifying objects of managed type through fixed pointers (§23.7).
  7. The content of memory newly allocated by stackalloc (§12.8.22).
  8. Attempting to allocate a negative number of items using stackalloc(§12.8.22).
  9. Implicit dynamic conversions (§10.2.10) of input parameters with value arguments (§12.6.4.2).

B.3 Implementation-defined behavior

A conforming implementation is required to document its choice of behavior in each of the areas listed in this subclause. The following are implementation-defined:

  1. The handling of the Unicode NULL character (U+0000) in a compilation unit. (§6.1)
  2. The behavior when an identifier not in Normalization Form C is encountered. (§6.4.3)
  3. The maximum value allowed for Decimal_Digit+ in PP_Line_Indicator. (§6.5.8)
  4. The interpretation of the input_characters in the pp_pragma-text of a #pragma directive. (§6.5.10)
  5. The values of any application parameters passed to Main by the host environment prior to application startup. (§7.1)
  6. The mechanism for determining whether a program is compiled as a class library or as an application. (§7.1)
  7. The policy or mechanisms used by an implementation for the creation and destruction of application domains. (§7.1)
  8. The exit code if the effective entry point method terminates due to an exception. (§7.2)
  9. Whether or not finalizers are run as part of application termination. (§7.2)
  10. Whether APIs allow a finalizer to be run more than once. (§7.9)
  11. Whether or not finalizers are run as part of application termination. (§7.9)
  12. The API surface provided by Expression<TDelegate> beyond the requirement for a Compile method. (§8.6)
  13. The precise structure of the expression tree, as well as the exact process for creating it, when an anonymous function is converted to an expression-tree. (§10.7.3)
  14. The reason a conversion to a compatible delegate type may fail at compile-time. (§10.7.3)
  15. The value returned when a stack allocation of size zero is made. (§12.8.22)
  16. Whether a System.ArithmeticException (or a subclass thereof) is thrown or the overflow goes unreported with the resulting value being that of the left operand, when in an unchecked context and the left operand of an integer division is the maximum negative int or long value and the right operand is –1. (§12.10.3)
  17. When a System.ArithmeticException (or a subclass thereof) is thrown when performing a decimal remainder operation. (§12.10.4)
  18. The impact of thread termination when a thread has no handler for an exception, and the thread is itself terminated. (§13.10.6)
  19. The mechanism by which linkage to an external method is achieved. (§15.6.8)
  20. The impact of thread termination when no matching catch clause is found for an exception and the code that initially started that thread is reached. (§21.4).
  21. An execution environment may provide additional attributes that affect the execution of a C# program. (§22.5.1)
  22. The mappings between pointers and integers. (§23.5.1)
  23. The effect of applying the unary * operator to a null pointer. (§23.6.2)
  24. The behavior when pointer arithmetic overflows the domain of the pointer type. (§23.6.6, §23.6.7)
  25. The result of the sizeof operator for non-pre-defined value types. (§23.6.9)
  26. The behavior of the fixed statement if the array expression is null or if the array has zero elements. (§23.7)
  27. The behavior of the fixed statement if the string expression is null. (§23.7)

B.4 Unspecified behavior

  1. The time at which the finalizer (if any) for an object is run, once that object has become eligible for finalization (§7.9).
  2. The representation of true (§8.3.9).
  3. The value of the result when converting out-of-range values from float or double values to an integral type in an unchecked context (§10.3.2).
  4. The exact target object and target method of the delegate produced from an anonymous_method_expression contains (§10.7.2).
  5. The layout of arrays, except in an unsafe context (§12.8.17.5).
  6. Whether there is any way to execute the block of an anonymous function other than through evaluation and invocation of the lambda_expression or anonymous_method-expression (§12.19.3).
  7. The exact timing of static field initialization (§15.5.6.2).
  8. The result of invoking MoveNext when an enumerator object is running (§15.14.5.2).
  9. The result of accessing Current when an enumerator object is in the before, running, or after states (§15.14.5.3).
  10. The result of invoking Dispose when an enumerator object is in the running state (§15.14.5.4).
  11. The attributes of a type declared in multiple parts are determined by combining, in an unspecified order, the attributes of each of its parts (§22.3).
  12. The order in which members are packed into a struct (§23.6.9).
  13. An exception occurs during finalizer execution, and that exception is not caught (§21.4).
  14. If more than one member matches, which member is the implementation of I.M (§18.6.5).

B.5 Other issues

  1. The exact results of floating-point expression evaluation can vary from one implementation to another, because an implementation is permitted to evaluate such expressions using a greater range and/or precision than is required (§8.3.7).
  2. The CLI reserves certain signatures for compatibility with other programming languages (§15.3.10).

End of informative text.