home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / educ / ada2for.doc < prev    next >
Encoding:
Text File  |  1988-05-03  |  1.4 KB  |  73 lines

  1. $ ! Demo of constraint checking across language boundaries
  2.  
  3. $ ! DEC Ada calling DEC FORTRAN-77
  4.  
  5. $ ! the Ada mainline:
  6.  
  7. $ type adamain.ada
  8.  
  9. WITH text_io;
  10. PROCEDURE adamain IS
  11.  
  12.     TYPE rint IS RANGE 1..10;
  13.     i : rint;
  14.  
  15.     PROCEDURE for1 (x : IN OUT rint);
  16.     PRAGMA interface (fortran, for1);
  17.  
  18.     PACKAGE int_io IS NEW text_io.integer_io(rint);
  19.  
  20. BEGIN
  21.     i := 8;
  22.     text_io.put ("Initial Value OF I IS ");
  23.     int_io.put (i,2);
  24.     text_io.new_line;
  25.     for1 (i);        --  assigns I:=20
  26.     text_io.put ("Value OF I after FOR1 IS ");
  27.     int_io.put (i,2);
  28.     text_io.new_line;
  29.     i := i + 1;    --  this should cause a constraint_error exception
  30.     text_io.put ("This should NOT be printed ");
  31.     int_io.put (i,2);
  32.     text_io.new_line;
  33. END adamain;
  34.  
  35. $ ! the FORTRAN subprogram:
  36.  
  37. $ type for1.for
  38.  
  39.         subroutine for1 (i)
  40.         i = 20
  41.         return
  42.         end
  43.  
  44. $ ! compile both
  45.  
  46. $ fortran for1
  47.  
  48. $ ada adamain
  49.  
  50. $ ! place FOR1.OBJ in MYLIB.OLB for later linking process
  51.  
  52. $ lib mylib for1/replace
  53.  
  54. $ ! do the link
  55.  
  56. $ acs link adamain mylib/lib
  57.  
  58. Invoking the VAX/VMS Linker
  59.  
  60. $ ! run the program:
  61.  
  62. $ run adamain
  63. Initial Value OF I IS  8
  64. Value OF I after FOR1 IS 20
  65. CONSTRAINT_ERROR
  66. Symbolic stack dump follows
  67.     ... detail left out ...
  68. $ ! note: the assignment back from FOR1 worked
  69.  
  70. $ !  the constraint error was raised when I did I:=I+1
  71.  
  72.