Enhanced C-Language Compatibility

The Enhanced C-Language Compatibility option changes a few compiler behaviors of the C# language in order to more easily port C code. These mainly affect compatibility between integers, booleans and pointers. It is controlled via the #pragma ccompatibility on Compiler Directive.

This option is not intended for general use, but for specific sections of code ported from the C language. It's effects are:

  • Integers, Pointers and and Floats become compatible with boolean, where 0 or null equals false. This e.g. allows pointers to be used as an if condition, as one would in classic C, C++ or Objective-C:
if (myObject)  // runs only if myObject is not nil
{
}
  • Method pointers become assignment compatible with Blocks, if the target is a block type.

  • Otherwise incompatibility pointer become assignment compatible without type checks. For example an Integer* can be assigned to a Float*, or vie versa.

  • The value Literal 0 becomes assignment compatible with enums and unmanaged pointers (essentially, it is treated as equivalent to null/nil.