title: Why does only one of my return tuple work but is fine when I print it out?
body: <p>I'm having trouble understanding why my return data is garbage when I don't use debug to print it out and is fine when I do print it out. I am using C++ make_tuple and tie on the other end for float values. If I don't include enough info let me know!</p>
  
  <p>I have tried checking for uninitialized data by printing out my functions. I also use this exact same code in other parts of the program with no issue.</p>
  
  <p>To give a background of what this program is. I am reading an adc value getting the max value (with error checking) and then sending it for a pass-fail for the system and display to the user. I can work around this in a few ways but I am mostly just curious about this bug.</p>
  
  <pre><code>std::tuple&lt;float,float&gt; hardware_control::hv_check()
  {
      float hv_filtered_max = 0;
      float hv_filtered_avg = 0;
  
      int samples = HV_SAMPLES;
      float hv_adc_read[samples];
      int non_zero_samples = 0;
      int i = 0;
      int loops = 0;
  
      //here we will take the a number of samples, average and find the max
      while((i &lt; samples) &amp;&amp; (hv_filtered_max &lt; HV_Voltage_MAX_CHECK)) // check if less than HV_MIN to speed up test (basically stop testing if it has passed the check)
      {
          hv_adc_read[i] = check_adc(7);
  
          if(hv_adc_read[i] &gt; 0 &amp;&amp; hv_adc_read[i] &lt; 10)
          {
            hv_filtered_avg += hv_adc_read[i];
            non_zero_samples++;
            i++;
          }
  
          if((hv_adc_read[i] &gt; hv_filtered_max) &amp;&amp; hv_adc_read[i] &lt; 10)
          {
              hv_filtered_max = hv_adc_read[i];
  
          }
  
          loops++;
  
          if(loops &gt; 500) // stop sampling at 500 if we never get anything (this is protection for it possibly freezing i we sample nothing)
          {
              hv_filtered_max = 0;
              break;
          }
      }
      hv_filtered_avg = hv_filtered_avg/non_zero_samples;
  
  return std::make_tuple(hv_filtered_avg,hv_filtered_max);
  }
  </code></pre>
  
  <hr>
  
  <pre><code>        hardware_control hwc;
  
          //where I call and return the data
          std::tie(Ins_Data.hv_avg,Ins_Data.hv_max) = hwc.hv_check();
  
          //Me printing out the values
          qDebug()&lt;&lt;"MAX_OUTSIDE"&lt;&lt;Ins_Data.hv_max&lt;&lt;endl;
  
          Ins_Data.hv_errors  = hwc.HV_error_check();
  
          log_data.push_back("HV_AVG");
          log_data.push_back(QString::number(Ins_Data.hv_avg*3));
          log_data.push_back("HV_MAX");
          log_data.push_back(QString::number(Ins_Data.hv_max*3));
  </code></pre>
  
  <p>Why this annoys me so bad is that every time I print it out with the qDebug() function it works! if I comment it out, it goes back to 3.8581*10^-38</p>
  
  <p>The value magically comes back to the correct value.</p>
  
  <p>What's going on here? My guess is the make_tuple and tie is corrupting the memory but if so then why is it only sporadically doing it? and why only one of the floats?</p>