C /CLI

C / CLI is a technology developed by Microsoft variant of the C language, which provides access to the virtual runtime environment. NET platform with the help of specially tailored language extensions.

C / CLI complies with the also developed by Microsoft specification called the Common Language Infrastructure ( CLI) for voice and platform - neutral development and execution of. NET applications. Programs that are written in C / CLI can be translated by the compiler into CIL intermediate code and run on the virtual machine. NET platform.

Since December 2005 there is an officially ratified by the ECMA standard for C / CLI.

Microsoft Visual Studio Version 2005 and the compiler front-end of the Edison Design Group offer an implementation of C / CLI.

The purpose of the extensions

Targets in the development of C / CLI were:

  • Creating an elegant syntax that fits well with the previous C . A programmer who is already familiar with C is "natural " feel the language extensions as possible.
  • Comfortable support of specific features of the CLI such as properties, events, generic types ( generics ), automatic garbage collection (garbage collection ), reference classes, etc.
  • Good support of language resources, which are distributed in the previous C , such as templates or " deterministic Deinitialisierungen ", and indeed for all types, including the new CLI classes.
  • Compatibility with existing C programs by the introduction of almost all pure extensions to ISO C .

Differences to Managed C

C / CLI is the result of a fundamental revision of Managed C , the first version of C language extensions for. NET platform. Managed C suffered from problems of acceptance, because many programmers felt the syntax extensions as difficult to read. For example, the syntax contained ingredients that could not clearly identify whether managed or unmanaged objects are created.

Which were introduced with managed C syntax elements for many programmers had provisionally integrated into the language. So, for example, were many keywords have been introduced that begin with two basic strokes. While this is common in language extensions to standard C , the large number of such keywords as well as their strong penetration in programs that made ​​use of the extensions, but had a disturbing effect on the overall image of the source texts.

Examples:

1) declaration of a function f that returns a CLI sequence ( array).

Destructors and finaliser

In contrast to Managed C destructor syntax ~ no longer mapped T () on the finalizer. Destructor and finalizer be distinguished in C / CLI; the finaliser now has the syntax! T (). The destructor is also identical to the function Dispose ( this was due to technical changes to the CLR allows ).

Other new features

Other new features of ISO - C : an improved enumeration ( enum class ), delegates, packaging ( boxing), interface classes, sealed classes, attributes, etc.

Object pointer

The most obvious change is the syntax ^ for the object pointer (sometimes called handles ). example:

T ^ = whole_object_pointer gcnew T ( a, b); Here is a gcnew operator for allocation of non- objects that are managed by the automatic garbage collection.

In comparison, the conventional syntax for pointers:

T * = new plain_old_pointer T ( a, b); Separation of de-initialization and deallocation:

Unlike ordinary pointers, the destructor is called when deleting object pointers ( handles) means delete, but not released the memory. Instead, the area occupied by the object store by the automatic garbage collection to the system is returned.

Here so the problematic Summary of management of memory and other resources In contrast to other languages ​​with automatic garbage collection ( such as C # or Java) is separated from each other: memory and other resources are not shared more with the aid of garbage collection ( " deterministic deinitialization "; see finalization).

When automatic variables that can be applied CLI objects:

Another technical innovation and one of the main differences to other languages ​​with automatic garbage collection are as automatic variables (ie, " on the stack " ) can be applied CLI objects. The lifetime of automatic variable ends at the moment in which they leave their scope.

In conjunction with the novel object pointers ( handles) frequently used programming techniques like RAII remain in C by ( short for. Resource acquisition is initialization ) can also be managed with automatic garbage collection CLI objects. Error-prone coding techniques as are known from other programming languages ​​, can be avoided with it.

Here is an example in C / CLI:

Void transmission ()    {      Message Queue source ( " server \ \ source queue" );      String ^ mqname = safe_cast ( source.Receive () body. );            Message Queue DEST1 ( " server \ \ " mqname ) dest2 ( " backup \ \ " mqname );      Message message = ^ source.Receive ();      dest1.Send ( message);      dest2.Send ( message);    } Explanation: Leaving the transmission function call ( with return or when an exception occurs ) objects implicitly to their function Dispose, in the reverse order in which they were constructed. In the example above dest2, DEST1 and then source. When an automatic object goes out of scope, or when deleting with delete, its destructor is called. The compiler then suppresses the call normally initiated by the automatic Speicherwaltung finalize function.

The elimination of Finalisierungsfunktionen can have an overall positive impact on the execution speed, but still helps to avoid other problems; problems when using the finalize function: see finalization.

In contrast to C / CLI a Dispose function for example, must always be explicitly called in Java resource release. In C # there are so -called Using blocks, at the end Deinitialisierungen be made. The Using blocks are indeed an improvement over the Dispose method of Java, but must always be mitangegeben, so they are the deterministic de-initialization of C / CLI also inferior.

Comparison with others. NET languages

A special feature of C / CLI is the miscibility of code that runs on the virtual machine, and code that runs directly on the CPU. Both types of program code can be compiled into a single executable. With this option takes C / CLI so far a special position among the. NET languages ​​.

Pictures of C /CLI

157203
de