Use registers as parameter? I'm writing a helper class to manage timers, and I'm writing a lot of code like

if (timer == 1)
        ICR1 = icr;
    else if (timer == 3)
        ICR3 = icr;
    else if (timer == 4)
        ICR4 = icr;
    else if (timer == 5)
        ICR5 = icr;


Is there a better way to store these registers?
e.g. an array

timers {
{ ICR1, TCCR1A, OCR1A, OCR1B },
{ ICR2, TCCR2A, OCR2A, OCR2B }


etc.

to be accessed like

timers[1][0]


for ICR1.

And ultimately, how would I assign a value? e.g.

*timers[1][0] = 100;


UPDATE:

I solved the problem with

volatile uint16_t* ICRs[5];
ICRs[1] = &amp;ICR1;
ICRs[3] = &amp;ICR3;
ICRs[4] = &amp;ICR4;
ICRs[5] = &amp;ICR5;

*ICRs[1] = x;
registers are nothing but pointers to memory addresses. so the best way to "parameterize" them is to do so via pointers.

assuming that ICRi is of 8-bit types - they are NOT to be sure:

uint8_t *ICRs[4];  //isr pointers

//initialize the icrs
ICRs[0]=(uint8_t *)&amp;ICR0;
ICRs[1]=(uint8_t *)&amp;ICR1;
...

*ICRs[i]=icr; //assign value to ICRi


note: that piece of code isn't operable in reality. The way to go is to use a pointer to void. But I'm sure you can figure that out.