0
int main(void) {

    TIM4_Init();
    setSysTick();

    while (1) {
        TIM4->CCR1 = 600;       // 600 == 0.6 ms  -> 0'
        Delay(700);

        TIM4->CCR1 = 1500;      // 1500 == 1.5 ms -> 90'
        Delay(700);

        TIM4->CCR1 = 2100;      // 2100 == 2.1 ms -> 150'
        Delay(700);
    }

    return 0; 
}

Above is part of the code I'm currently working on. I'm getting a warning saying that 'Statement is unreachable' at the Return 0, and I couldn't figure out why.

Bence Kaulics
  • 7,066
  • 7
  • 33
  • 63
lightworks
  • 21
  • 1
  • 9

2 Answers2

4

The while (1) loops forever, so without a way to get out if the loop, you won't get to the return.

To get rid of the warning, you can change main() to return void

void main (void) { }

Justin J.
  • 396
  • 2
  • 12
  • 1
    `void main` is a non-standard C. It might be available as an extension though. – Eugene Sh. Apr 27 '17 at 20:20
  • void main(void) is allowed since C99, and required for some microcontrollers. However, may be compiler specific. [See discussion about int main() vs void main()](http://stackoverflow.com/a/9356660/7928083) – Justin J. Apr 27 '17 at 23:38
  • Wrong!! The return value is needed in some toolchains (actually in the exit code) to determine how to end the program. main is not a part of compiler - it is just called by the startup code. C99 standard advices int return value - but it can be implementation defined as well. – 0___________ Apr 29 '17 at 13:53
1

Delete return 0; :) The compiler will notice that there is no way to reach end of main(), and it will not generate warning for reaching the end of int function without the return

0___________
  • 60,014
  • 4
  • 34
  • 74