M
ma740988
Referencing source below, depending on the value of a bitset object,
for the range 0..3, I call a function interrupt0, for the range 4..7 I
call a function interrupt1. I'd prefer to just call an 'interrupt'
function within the for loop. Within the interrupt function I'll then
call the appropriate interrupt0 and/or interrupt1 function. One idea
surrounds using a min/max range and perhaps a pointer to the
appropriate function. For instance.
For the range 0..3; I'll call function interrupt0, Similarily, for
the range 4..7, I'll call function interrupt1.
Suggestions on how I could achieve this and/or an alternate approach
would be appreciated. Thanks in advance
# include <bitset>
void interrupt0 ( int val ) {
printf ( "o" );
}
void interrupt1 ( int val ) {
printf ("x" );
}
int main() {
std::bitset < 8 > bmask_obj ( 0xFF );
for ( std::size_t odx ( 0 ) ; odx < bmask_obj.size(); ++odx ) {
if ( bmask_obj [ odx ] ) {
if ( odx < 4 ) {
interrupt0 ( odx ) ;
} else if ( odx >= 4 && odx < 8 ) {
interrupt1 ( odx );
}
}
}
}
for the range 0..3, I call a function interrupt0, for the range 4..7 I
call a function interrupt1. I'd prefer to just call an 'interrupt'
function within the for loop. Within the interrupt function I'll then
call the appropriate interrupt0 and/or interrupt1 function. One idea
surrounds using a min/max range and perhaps a pointer to the
appropriate function. For instance.
For the range 0..3; I'll call function interrupt0, Similarily, for
the range 4..7, I'll call function interrupt1.
Suggestions on how I could achieve this and/or an alternate approach
would be appreciated. Thanks in advance
# include <bitset>
void interrupt0 ( int val ) {
printf ( "o" );
}
void interrupt1 ( int val ) {
printf ("x" );
}
int main() {
std::bitset < 8 > bmask_obj ( 0xFF );
for ( std::size_t odx ( 0 ) ; odx < bmask_obj.size(); ++odx ) {
if ( bmask_obj [ odx ] ) {
if ( odx < 4 ) {
interrupt0 ( odx ) ;
} else if ( odx >= 4 && odx < 8 ) {
interrupt1 ( odx );
}
}
}
}