View Single Post
Copernicus's Avatar
Posts: 1,986 | Thanked: 7,698 times | Joined on Dec 2010 @ Dayton, Ohio
#2
Originally Posted by pichlo View Post
  • Add a declaration of something involved at the beginning of the function. It does not need to be used, as long as the con/destructor is being called. An int was not enogh, but e.g. an QStringList did the trick.
  • Split the string literal in one of the blue lines to something like QString("k") + "Hz".
  • Change switch(index) to switch(index+1), with obvious changes to the case labels.
Hmm, I wonder if there's some magic involved with the indexing here, especially considering the last item on that list. C compilers can try to do some pretty crazy optimization on switch statements, so yeah, I can believe that the compiler might make a mistake somewhere...

Can you provide some info as to how FREQUENCY and PERIOD are defined? Are they #defines, enums, variables? What are their values? (GCC might be utilizing the raw values in its jump tables, which is why their values could be interesting.)

I haven't personally done any assembler or compiler stuff in a very, very long time, so take anything I say with a grain of salt. But, I just did a quick google search to refresh my memory on the subject; here's an interesting description of why to be wary of the switch statement:

http://embeddedgurus.com/stack-overf...ch-statements/


On another topic, if there are only two possible values, it might be easier to just skip the switch statement altogether. An if/else statement should be just as efficient, if not more so:

Code:
if (index == FREQUENCY)
{
// Add the Hz items
}
else
{
// Add the Seconds items
}

Last edited by Copernicus; 2014-06-12 at 01:20.
 

The Following User Says Thank You to Copernicus For This Useful Post: