MULTI.MOD 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. MODULE multi;
  2. (* multi-language demonstration program *)
  3. (* demonstrates how to call C from Modula and vice versa *)
  4. (* There are 3 modules, implemented by the following source files *)
  5. (* multi.mod : main module) *)
  6. (* multi1.c, multi1.def : module written in C, called from Modula *)
  7. (* multi2.mod, multi2.def, multi2.h : module written in Modula, called from C *)
  8. FROM math IMPORT atan2;
  9. FROM stdlib IMPORT system;
  10. FROM stdio IMPORT printf;
  11. IMPORT IO;
  12. IMPORT multi1;
  13. CONST NL = CHAR(10);
  14. CONST pi = 3.141592654;
  15. VAR x,y:LONGREAL;
  16. BEGIN
  17. IO.WrStr("IO.WrStr called from Modula" );
  18. IO.WrLn;
  19. multi1.x(1,2,3,4);
  20. multi1.y(1,2,3,4);
  21. system('dir multi*.*'); (* C system function (quite convenient) *)
  22. x := 1.2;
  23. y := 1.2;
  24. printf( "atan2(%f,%f) = %f, pi/4=%f" + NL, x, y, atan2(x,y), LONGREAL(pi/4.0) );
  25. (* Note that you cannot use "\n" in string constants because this
  26. is a compile-time notation of the C language, instead use
  27. string concatenation of NL *)
  28. (* Also note that REAL arguments for printf have to be converted to LONGREAL,
  29. since this is what printf expects *)
  30. END multi.