diff liboctave/cruft/misc/f77-fcn.h @ 22843:a2809b2938d6

* f77-fcn.h (to_f77_int): New inline function.
author John W. Eaton <jwe@octave.org>
date Tue, 29 Nov 2016 01:00:15 -0500
parents 60405b73e439
children 5126040e8f49
line wrap: on
line diff
--- a/liboctave/cruft/misc/f77-fcn.h	Tue Nov 29 00:32:35 2016 -0500
+++ b/liboctave/cruft/misc/f77-fcn.h	Tue Nov 29 01:00:15 2016 -0500
@@ -25,9 +25,14 @@
 
 #include "octave-config.h"
 
+#include "lo-error.h"
 #include "quit.h"
 
 #if defined (__cplusplus)
+#  include <limits>
+#endif
+
+#if defined (__cplusplus)
 extern "C" {
 #endif
 
@@ -364,6 +369,24 @@
                            F77_CHAR_ARG_LEN_DECL);
 
 #if defined (__cplusplus)
+
+inline F77_INT
+to_f77_int (octave_idx_type x)
+{
+  // FIXME: How to do this job in C, not knowing in advance the actual
+  // type of F77_INT?
+
+  if (x < std::numeric_limits<F77_INT>::min ()
+      || x > std::numeric_limits<F77_INT>::max ())
+    (*current_liboctave_error_handler)
+      ("integer dimension or index out of range for Fortran INTEGER type");
+
+  return static_cast<F77_INT> (x);
+}
+
+#endif
+
+#if defined (__cplusplus)
 }
 #endif