HOMEWORK PROBLEM 11 INTRODUCTION TO Ada 95 PURPOSE: To learn about: Passing subprograms as arguments to other subprograms. Record discriminants. Interfacing to other languages. END RESULT: A complete Ada program that is a main procedure that expands on one of the three subjects in the PURPOSE: EXTRA CREDIT: Expand on any two of the three subjects in the PURPOSE. PROBLEM: Use the attached samples as a guide and expand on the sample. If you want to experiment with interfacing to other languages, you need a compiler on your machine for the other language. Note: gnat always comes with a C compiler, gcc. The file discrim.ada needs to be gnatchoped, then see comments. Basically add Rectangle: to the enumeration type, to the record, to the bodies of the functions. Then uncomment the use of Rectangle in the main procedure. TURN IN: Printout of your code and output from execution. OBSERVE: All of these subjects have special cases. keep it simple and avoid the corners of the language. READING : ISO 8652:1995 Just finish reading any unread sections. Barnes 6.6, 16., 21. FILES: The starter files are in this handout. Records with discriminates The main concept of a discriminated record is that a record of this type may contain one of a number of sets of values. This is something like a C union, but is safe because you can not access a component that is not present. The main restriction is that a component name can only be used once in any record type definition. Remember, when initializing or storing into a discriminated record, you have to set the discriminant value(s) in the aggregate along with the values for that discriminants components. Examples follow in discrim.ada and disc.adb Interfacing Ada programs to other languages and visa versa Ada 95 Library Packages related to interfacing: Interfaces Interfaces.C Interfaces.C.Pointers Interfaces.C.Strings Interfaces.COBOL Interfaces.Fortran Other packages you may need to get down and dirty: System System.Address_To_Access_Conversion System.Machine_Code System.RPC System.Storage_Elements System.Storage_Pools Some nitty gritty is covered in the makefile makela The simplest example is interf.adb that uses c_funct.c, then interfex.adb, c_funct2.c, a_funct2.ads, a_funct2.adb, then cxbcm.adb that uses cmfinc.f . Passing functions and procedures as parameters. The most common uses are to do numerical integration or minimization processes. The simple trick is to declare an access type for the subprogram specification, then pass the subprogram'access as the parameter. The sticky language issue is that the access type has to be defined at the same scope level where it is used. Generics get around this problem. For a homework problem, write a function of your own and pass it to another function you write. This can all be in one .adb file like integrat.adb (DOS file name)