{standard input}: Assembler messages:
{standard input}:766: Error: bad instruction `orn r3,r3,#127'
make: *** [waveform.o] Error 1
void WaveForm::on_comboFreqPeriod_currentIndexChanged (int index)
{
ui.comboFreqPeriodUnit->clear();
switch (index)
{
case FREQUENCY:
ui.comboFreqPeriodUnit->addItem("Hz");
ui.comboFreqPeriodUnit->addItem("kHz");
break;
case PERIOD:
ui.comboFreqPeriodUnit->addItem(micro + "s");
ui.comboFreqPeriodUnit->addItem("ms");
ui.comboFreqPeriodUnit->addItem("s");
break;
default: // impossible but let's keep gcc happy
break;
}
ui.comboFreqPeriodUnit->setCurrentIndex(1);
}
| The Following 2 Users Say Thank You to pichlo For This Useful Post: | ||
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:
An if/else statement should be just as efficient, if not more so:if (index == FREQUENCY)
{
// Add the Hz items
}
else
{
// Add the Seconds items
}
| The Following User Says Thank You to Copernicus For This Useful Post: | ||
| The Following 2 Users Say Thank You to pichlo For This Useful Post: | ||
IMHO, the best value of an enum is to make clear which of a variety of states your code is in. (This is Pichlo's quite valid criticism of my if/then suggestion, as I skipped the use of one of his two enum values.) If you hide the code inside the enum declaration itself, you're basically moving from declaring a set of states to declaring a set of function pointers, which is a very different beast.
I think it'd be better to go all the way and create a set of sibling classes. Something like this:class indexType
{
public:
virtual void addItems() = 0;
};
class frequency: public indexType
{
public:
void addItems(); // Add the Hz items
};
class period: public indexType
{
public:
void addItems(); // Add the Seconds items
};
| The Following 2 Users Say Thank You to Copernicus For This Useful Post: | ||
static void refillComboBox (QComboBox *combo,
const QString items[],
int number_of_items,
int selected_item);
#define ITEMS(x) sizeof x / sizeof x[0]
static const QString foo[] = { "Hz", "kHz" };
refillComboBox(ui.comboBlaBlaBla, foo, ITEMS(foo), 0 };
static const QString bar[] = { micro + "s", "ms", "s" };
refillComboBox(ui.comboBlaBlaBla, bar, ITEMS(bar), 3 };
| The Following 2 Users Say Thank You to pichlo For This Useful Post: | ||