// Unfortunately Imp to C has no way of automatically knowing that
// a file of external routines is to be compiled into a library
// so our choices are to compile all files of external routines
// twice - once as a static object and once as a library - *or*
// just leave that choice up to the user.

// If we allowed language changes it could be done, eg if we
// declared the procedure as a "%dynamicrealfn hypotenuse(%longreal x0, y0, x1, y1)"
// rather than an external, *or* we added a new "%library hypot"
// statement as in Algol 60 and possibly Atlas Autocode.

// Compile with:
//    gcc -c -fPIC hypot.c
//    gcc -shared -Wl,-soname,hypot.so.1 hypot.o -o hypot.so.1.0 -lm

// Note the use of -lm (etc) to link any externals called by this module
// which are not themselves %dynamic ... if we don't partially pre-link,
// *every* call in this module will have to be satisfied dynamically,
// even if declared explicitly as "%externalroutinespec ..."

//%externallongrealfnspec sq rt %alias "sqrt" (%longreal x)
//   (sq rt was not in my current imp2021 library, so I was calling C from Imp directly.)
extern double sqrt(double x);

//%externallongrealfn hypotenuse(%longreal x0, y0, x1, y1)
double hypotenuse(double x0, double y0, double x1, double y1) {
  //  %result = sq rt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0))
  return sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0));
//%end
}

//%endoffile
