chapter 4


1) Enumeration
• An enumeration types is one in which the user enumerates all of the possible values, which are symbolic constants.
• In this all possible values are named constants and are enumerated in the definition. (called enumerated constants )
• In Ada a typical enumeration type is shown as: Type DAYS is {M,T,W,Th,F,Sa,S}
• In C,
- enum colors { red=1 , blue, green, yellow, pink, black}; colors mycolor = blue;
• Advantages : more readable program.
• Disadvantages in C#, Java : - no arithmetic operations are legal on enumeration types.     

subrange

• A subrange type is an ordered contiguous subsequence of an ordinal type.
• These types were introduced by Pascal.
• In Pascal ,
type DaysOfWeek = (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday,
Saturday); DaysOfWorkWeek = Monday..Friday;
• In Ada,
type Days is (mon, tue, wed, thu, fri, sat, sun);
subtype weekdays is Days range mon…….fri;
• Advantages:
• More readable program
• Reliablity

           Array types

• An array is a homogeneous aggregate of data elements in which an individual element is identified by its position in the aggregate.  

1. Static array :• subscript ranges are statically bound and storage allocation is static.
• advantage: efficiency
• eg. Arrays declared in C, C++ using static modifier.
2. Fixed stack-dynamic array : • subscript ranges are statically bound.
• storage allocation is done at elaboration time.
• Ex. Arrays declared in C and C++ functions 
3. Stack dynamic array : • Subscript ranges and the storage allocation are dynamically bound at
elaboration time.
• Once the subscript ranges are bound and the storage is allocated they remain fixed during the lifetime of the variable.
• adv. : flexibilility.
Ex. Supported by Ada 
4. Fixed heap-dynamic array: • Both the subscript ranges and storage binding are done when the user program requests them during execution.
• storage is allocated from the heap.
• Supported by Fortran-95.
• eg. Array in C or C++ using malloc, new resp.
5. Heap dynamic array : • The binding of subscript ranges and storage allocation is dynamic and can change any number of times during array’slifetime.
• Adv. – arrays can grow and shrink during program execution.
• supported by C#, Javascript, Perl 

Record Types
• A record (struct in C) is possibly a heterogeneous aggregate of data elementsin which the individual elements are identified by names.
• Design issues are : – What is the syntactic form of references to fields?
– Are elliptical (indirect) references allowed?

Discriminated VS Free union
• In Fortran the Equivalence statement is used to specify unions.
• In C, C++ ,the unions are called free unions, because
programmers are allowed complete freedom from type checking in their use.
• Type checking of unions requires that each union construct include a type indicator.
• Such an indicator is called a tag or discriminant and a union with a discriminant is called discriminated union.
• Pascal allows the user to specify variables of a variant record type, that will store only one possible type values in the variant.              

Comments

Popular posts from this blog

dot net

What is research problems

What do you mean by research design