implementation suggestions

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 );
}
}
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top