Timer 1 compare interrupt

Hello,
I have a weird little problem with the CTC mode of Timer1.
if I define the OCR1A register before the TCCR1A register the program does not work.

--------- This is OK -------
TCCR1A = B00000000;
OCR1A = 31249; // cycle = 31250 * 16us

------- This is not OK -------
OCR1A = 31249; // cycle = 31250 * 16us
TCCR1A = B00000000;

volatile byte TOC=LOW;
void setup(){
    pinMode(13,OUTPUT);    
    TCCR1A = B00000000;    
    OCR1A = 31249;// cycle=31250*16us    
    TIMSK1 = B00000010; // Enable CTC interrupt
    TCCR1B = B00001100;  //CTCmode,Th=16us    
}
void loop() { 
    if(TOC){
       digitalWrite(13,!digitalRead(13));
       TOC=LOW;
    }
}
ISR(TIMER1_COMPA_vect) {
    TOC=HIGH;
}

It is quite confusing to read the already very cryptic AVR code if you don't use (1 << SomeBitName) e.g.
TIMSK1 = (1<< OCIE1A);

Apart from that, TCCR1A is already all-zeros by default (see datasheet 16.11.1) so why do you set it to all zero's in the first place?

Apparently you also did not enable interrupts (sei() or setting bit 7 of SREG to 1).

Thank you for reply.
I added sei () but the program still doesn't work.
What is strange is that the order of assignment of these two registers should not influence the operation of the program.

volatile byte TOC=LOW;
void setup(){
    pinMode(13,OUTPUT);
    cli();    
    OCR1A = 31249;// cycle=31250*16us    
    TCCR1A = B00000000;    
    TIMSK1 = B00000010; // Enable CTC interrupt
    TCCR1B = B00001100;  //CTCmode,Th=16us 
    sei();   
}
void loop() { 
    if(TOC){
       digitalWrite(13,!digitalRead(13));
       TOC=LOW;
    }
}
ISR(TIMER1_COMPA_vect) {
    TOC=HIGH;
}

but this version works

volatile byte TOC=LOW;
void setup(){
    pinMode(13,OUTPUT);
    cli();    
    TCCR1A = B00000000;    
    OCR1A = 31249;// cycle=31250*16us    
    TIMSK1 = B00000010; // Enable CTC interrupt
    TCCR1B = B00001100;  //CTCmode,Th=16us 
    sei();   
}
void loop() { 
    if(TOC){
       digitalWrite(13,!digitalRead(13));
       TOC=LOW;
    }
}
ISR(TIMER1_COMPA_vect) {
    TOC=HIGH;
}

What is strange is that the order of assignment of these two registers should not influence the operation of the program.

I agree, but it does.

Experienced users have learned that when setting up the timer, clear TCCR1A before doing anything else.

Don't forget that the bootloader runs before your program, and may set many registers to unwanted values. You should not assume that reset conditions from the data sheet apply unless you use an ISP programmer.