chiark / gitweb /
avoid using HUGE_VAL to initialize global variable
authorAmro <amroamroamro@gmail.com>
Sun, 11 Sep 2016 14:33:14 +0000 (17:33 +0300)
committerAmro <amroamroamro@gmail.com>
Tue, 13 Sep 2016 18:24:26 +0000 (21:24 +0300)
in some older C (not C++) compilers, HUGE_VAL macro is not
always a constant expression (VS2010 is in this category)

Only C99 (section 7.12) guarantees the macro to expand
to a constant expression but not C90 (section 7.5)

test/box.c

index 61596d40faa8e0886dacf09f9a138e85895bee0c..ebe728e030ce189b991975742f0045048b1090d2 100644 (file)
@@ -125,12 +125,12 @@ static double box_constraint(int n, const double *x, double *grad, void *data)
      return 0;
 }
 
-static const double box_lb[5] = {0,1.2,20,9,6.5};
-static const double box_ub[5] = {HUGE_VAL, 2.4, 60, 9.3, 7.0};
-static const double box_xmin[5] = {4.53743, 2.4, 60, 9.3, 7.0};
-
 int main(void)
 {
+     const double box_lb[5] = {0,1.2,20,9,6.5};
+     const double box_ub[5] = {HUGE_VAL, 2.4, 60, 9.3, 7.0};
+     const double box_xmin[5] = {4.53743, 2.4, 60, 9.3, 7.0};
+
      int cdata[6] = {-1,1,-2,2,-3,3};
      double x[5] = {2.52, 2, 37.5, 9.25, 6.8};
      double minf;