changeset 11663:3f5a67e8215c release-3-0-x

oct-rand.cc (get_dist_id): initialize retval
author John W. Eaton <jwe@octave.org>
date Tue, 26 Feb 2008 18:46:14 -0500
parents a4d0680f4dda
children 7fde54a3e0ce
files liboctave/ChangeLog liboctave/oct-rand.cc
diffstat 2 files changed, 12 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/ChangeLog	Tue Feb 26 05:30:39 2008 -0500
+++ b/liboctave/ChangeLog	Tue Feb 26 18:46:14 2008 -0500
@@ -1,5 +1,10 @@
 2008-02-26  John W. Eaton  <jwe@octave.org>
 
+	* oct-rand.cc (unknown_dist): New dist type.
+	(uniform_dist, normal_dist, expon_dist, poisson_dist, gamma_dist):
+	Use static const int instead of #define.
+	(get_dist_id): Default retval is unknown_dist.
+
 	* oct-rand.cc (rand_states): New static variable.
 	(initialize_rand_states, get_dist_id, get_internal_state,
 	set_internal_state, switch_to_generator, save_state): New functions.
--- a/liboctave/oct-rand.cc	Tue Feb 26 05:30:39 2008 -0500
+++ b/liboctave/oct-rand.cc	Tue Feb 26 18:46:14 2008 -0500
@@ -39,13 +39,12 @@
 #include "randgamma.h"
 #include "mach-info.h"
 
-// Possible distributions of random numbers.  This was handled with an
-// enum, but unwind_protecting that doesn't work so well.
-#define uniform_dist 1
-#define normal_dist 2
-#define expon_dist 3
-#define poisson_dist 4
-#define gamma_dist 5
+static const int unknown_dist = 0;
+static const int uniform_dist = 1;
+static const int normal_dist = 2;
+static const int expon_dist = 3;
+static const int poisson_dist = 4;
+static const int gamma_dist = 5;
 
 // Current distribution of random numbers.
 static int current_distribution = uniform_dist;
@@ -188,7 +187,7 @@
 static int
 get_dist_id (const std::string& d)
 {
-  int retval;
+  int retval = unknown_dist;
 
   if (d == "uniform" || d == "rand")
     retval = uniform_dist;