Question
Should main return 0 when there is a while(1) ?
Hi all,
I'm programming an embedded software.
According to C standards, I write :
int main(void)
{
// Init
initMethod();
/* Main loop */
while (1)
{
execute();
}
// This return is never reached
return 0;
}
But when my code is analyzed by SonarQube, I have a bug report: 'return' will never be executed.
To fix it, I would write the following:
int main(void)
{
// Init
initMethod();
/* Main loop */
while (1)
{
execute();
}
}
But I'm annoyed with the fact that the main method doesn't have the "good" return type.
What is the good pratice in this case ?
Best regards.