Introduction to C / CLI
One place for hosted C (MC ) is a place in the grammar format and ordinary programming language. Many people have evaluated: ugly and twisted syntax.
Because of .NET's foundation, CommON Language Infrastructure CLI is submitted to the ECMA Standards Committee. In order to improve the existing MC ECMA, a new working group was started in October 2003, which provided a set of new language extensions for the interactive operation between the ISO standard C and CLI. This is the origin of C / CLI.
MC before the improvement has the following shortcomings:
1, the syntax format is not anger, such as the keywords of many double underscores;
2, the hosted C is interacting with CLIs that all functions can be used, such as spell-each grammar in C # or VB.NET, and MC cannot be;
3, MC provides some standard C language characteristics, such as: Templates in C , and CLI's memory collection;
4, the unmanaged pointer and the hosted reference pointer are used in grammar, which is easy to confuse;
5, the effect of the MC compiler is not good.
The current C / CLI is also MC in Whidbey, completely solves the problem of Ugly and Twist above.
Let's introduce some features:
Start from HelloWord:
void_tmain ()
{
// ^ is a newly introduced grammar, indicating a handler
String ^ str = "Hello World";
Console :: WriteLine (STR);
}
Solver ^ Str handler indicates a reference to a managed object.
The difference between Handler and C is as follows:
1, use ^ and * in grammar;
2, Handler is a reference to a (CLI) management of the hosted stack, and the pointer points to a physical memory address;
3, the pointer is not affected by the garbage collector, and the memory address that the Handler actually pointed to collect garbage collectors;
4. Use the pointer to use Delete to release the memory, and the handler can use it or use;
5, Handler is a type of security, each of which pointing to the Handler of the managed object corresponds to a specific type, and the pointer does not require, for example, the Void * pointer can be used;
6. Use new NEW to return a pointer on the syntax, and GCNEW returns a handler.
Please see the example below:
void_tmain ()
{
String ^ str = GCNEW STRING ("Hello World");
Object ^ O1 = GCNEW Object ();
Console :: WriteLine (STR);
}
The above case GCNew is used to initialize a managed object on the CLR pile and return a handler. Such syntax can be distinguished from the declaration of the pointer.
Look at a specific example:
Using Namespace System;
Interface Class IDog
{
Void bark ();
}
Ref class dog: idog
{
PUBLIC:
Void bark ()
{
Console :: WriteLine ("Wang");
}
}
Void_tmain () {
DOG ^ D = gcnew dog ();
D-> bark ();
}
It looks very comfortable, yes
Tian Chunfeng
2004-10-14
Original address:
Here
http://www.winterdom.com/cppclifaq/
September 17 Stan Lippman Interview Chattelet