tags:

views:

105

answers:

1

HI all,

I am a beginner in the ada language.I have an short piece of code.Can anyone please tel me what does it mean?

type Myarr_Type is array (Character) of Character;

  Myarr : Myarr_Type;
  C1 : character := character'first;
  C2 : character := character'last;

My question is 1)What does C1 and C2 contain according to the above code?

Please do excuse if this is really silly.I dont have an ada compiler to check the contents of this variable

Regards Maddy

+3  A: 

The 'first and 'last attributes of a type indicate the first and last values of the range covered by the type. In this case, C1 is character'val(0) and C2 is character'val(255) (character is an 8-bit character type).

You can read more about these "Language Defined Attributes" in Annex K of the Ada 95 Reference Manual.

Greg Hewgill
Greg,I jst thought that C1 would be representing the A and C2 would be Z.This short piece of code will show: while Array_not_Filled loop Myarr(Ndx) := C1; C1 := Character'succ(C1); Ndx := Character'succ(NDX); Array_not_Filled := not (C1 = C2); end loop;
maddy
@Greg: You are correct. I see in the section 3.5.2 of the reference manual where it defines `Character` as having 256 values.
Matthew T. Staebler
@maddy: `character` holds more than just letters. You will probably find that your `Myarr` has 256 elements.
Greg Hewgill