LocalReduce: Initialize variables to avoid compiler warnings

Issue #604 closed
Frank Löffler created an issue

The following one-line change would initialize the inval variable, avoiding compiler warnings for almost all variable types.

Index: local_reductions.h
===================================================================
--- local_reductions.h  (revision 86)
+++ local_reductions.h  (working copy)
@@ -32,6 +32,7 @@
   iter = 0;                                                                       \
   sum_indices = 0;                                                                \
   num_points = 1;                                                                 \
+  REDUCTION_INITIAL(inval)                                                    \
   REDUCTION_INITIAL( * outval)                                                    \
                                                                                   \
   if ( N_dims == 0 )                                                              \

Keyword:

Comments (8)

  1. Erik Schnetter
    • removed comment

    I mean, is this a real possibility in the source code, or is the compiler just not clever enough to understand the source code? I notice e.g. some funny games with .Re and .Im and complex numbers.

  2. Frank Löffler reporter
    • removed comment

    It complains about .Im, also for non-complex variable types, so I assume it's the compiler not understanding the logic. However, I didn't look too closely and it might actually access .Im even for non-complex types. It doesn't look bad to me to initialize that memory in any case, and it also does not look like it would affect performance in any measurable way (by looking at the code, not by trying to measure it).

  3. Erik Schnetter
    • removed comment

    There is a bit of complexity since e.g. the L2 norm of complex numbers results in a real number. I don't know how/whether the code handles this.

    I also remember that some of the reduction operations give wrong values for complex numbers.

    The patch seems harmless, please apply.

  4. Log in to comment