1 / 13

The Cn Language over view

The Cn Language over view. The Cn language strongly on ANSI C . So if you are familiar with ANCI it is not so tough to deal with Cn language . Basic Data types: char, unsigned char, signed char. short, unsigned short, signed short. int, unsigned int, signed int.

pcloud
Download Presentation

The Cn Language over view

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Cn Language over view The Cn language strongly on ANSI C . So if you are familiar with ANCI it is not so tough to deal with Cn language . Basic Data types: char, unsigned char, signed char. short, unsigned short, signed short. int, unsigned int, signed int. long, unsigned long, signed long. float, double Cn also supports the following aggregate types: structute union pointer arrays Note : These are exactly same as for ANSI C.

  2. Mono and poly specifiers These are the added two features which we will found in Cn language. These keywords are called multiplicity specifiers. • mono: The declaration exists in mono domain (i.e. one instance ) e.g. mono variable/memory . • poly: The declaration exists in poly domain (i.e. many instance ) e.g. poly variable/memory. Note default multiplicity is mono. Basic types. The basic types can always be used in conjunction with multiplicity specifiers. For instance: poly int counter; //A different instance of ’counter’ exists on each PE mono unsigned char initial; // A single instance of ’initial’ exists

  3. Example

  4. Pointers Type As we have done pointers in traditional C language const int * const foo; /* const pointer to const int */ int * const bar; /* const pointer to non-const int */ const int * bing; /* non-const pointer to const int */ Multiplicity specifiers work in similar way poly int * poly foo; /* poly pointer to poly int */ int * poly bar; /* poly pointer to mono int (equiv to mono int * poly bar) */ poly int * bing; /* mono pointer to poly int (equiv to poly int * mono bing) */ mono int * mono p; /* mono pointer to mono int */

  5. Mono pointer to mono data : Poly pointer to mono data : Pointers to mono data

  6. Mono pointer to poly data: A mono ptr to poly memory (poly*mono) Example : poly char buffer[BUFFER_SIZE] poly char * mono ptr; poly int count; int i; ptr = buffer;// Initialize count = 0; for (i = 0; i < BUFFER_SIZE; i++) { if (*ptr == 0) //check value pointed to each PE { count++;// increment the counter } ptr++;// move the pointer to next byte } Pointer to poly dataFor poly data, the same two types ofpointers exist: mono pointer points to the same address in every PE’s memory. poly pointer can hold a different address on each PE (pointing to data on the same PE).

  7. Mono pointer to poly data : The type is (poly * poly) Example: // prototype for poly version of strchr() poly char * poly strchrp(const poly char * mono s1, poly char c); poly char str[256];// variable str is actually a poly * mono pointer poly char * poly ptr;// a pointer into string ......... // initialize string on each PE ptr = strchrp(str, ’z’);// search for first occurrence of ‘z’ different on each PE Continue……

  8. Illegal Cast We have to take a note that , because mono and poly data are in completely separate memory space , it is not legal to cast or assign a mono * pointer, or vice-versa. Problems in doing so: • The mono and poly pointer sizes are not guaranteed to be the same; poly memory is typically quite small and may use 16-bit pointers, while mono pointers may be 32 or 64 bits . • A pointer to data in poly memory, for example, will not necessarily point to anything meaningful if cast to a pointer to mono memory; it could point to arbitrary data or even code.

  9. Arrays Array types : The multiplicity specifier for an array type defines the domain for the base type. Example :poly char buffer[20] ; • The declaration will create space for 20 characters on the poly stack frame. • The address of each of these arrays in poly space will be same . Note : It is not possible to create a poly char * poly pointer using array notation since an array only specifies the base type multiplicity class ( the implicit pointer multiplicity class will always be mono). The multi dimension array are supported in Cn language as we have done in ANSI C.

  10. Structure and Union • They are same as ANSI C . • But multiplicity specifiers have strict rules for use inside the structure / union . • Objects inside a structure /union definition have no multiplicity class. Like : struct _A { int a; char b; // Multiplicity class not defined in struct definition float c; }; poly struct _A my_struct; // All objects within the struct are poly mono struct _A my_struct_2; // All objects within the struct are mono But : poly struct _B { int a; // Not allowed to declare multiplicity inside definition int b; // (but statment also declares a poly object) } my_struct_3;

  11. Structure and Union Cont ……. Even the following syntax is also wrong : union _B { poly int a; // Illegal use of multiplicity specifier mono char b; // Illegal use of multiplicity specifier float c; }; mono union _B my_union; // Multiplicity of declaration would conflict with definition • Only at the time of pointer declaration in structure/union the poly and mono can be used. • Because the member itself (the pointer) cannot have a multiplicity specifier, but the object pointed to can • Without this capability it would not be possible to have a pointer to a poly object as a member of a structure or union.

  12. Structure and Union Cont ……. Example : struct _C { mono int *a; // pointer to a mono int poly char *b; // pointer to a poly char }; struct _C my_struct2; // Note: this is an implicit mono object // a is mono pointer to mono int // b is mono pointer to poly char struct _C poly my_struct3; // Poly object of the same type // a is poly pointer to mono int // b is poly pointer to poly char The first object my_struct2 contains two members which are mono int * mono a and poly char * mono b. The second object my_struct3 contains two members which are mono int * poly a and poly char * poly b

  13. Typedefs • Cn supports typedefs as of ANSI C • The typedef statement cannot use multiplicity specifiers to define the multiplicity of the type. • But as with structs and unions, it can define pointers to mono or poly types. Like : typedef poly int p_int; // illegal use of multiplicity specifier typedef poly int * p_ptr; // ’p_ptr’ is a pointer to poly int typedef mono int * m_ptr; // ’m_ptr’ is a pointer to mono int p_ptr a; // poly int * mono a poly p_ptr a; // poly int * poly a m_ptr a; // mono int * mono a poly m_ptr a; // mono int * poly a

More Related