C Language main()

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

C Language main()

453 Views
QJ_HAPPY
Contributor I

Why is the endless loop in the main function is :

for (;;)
{
if (exit_code != 0)
break;
}
return exit_code;

and What causes exit_code = -1?

0 Kudos
2 Replies

440 Views
JRoberto
NXP TechSupport
NXP TechSupport

Hi @QJ_HAPPY 

The code that you get from the main function is just a template. That you can use or not.

Normally, you want the software of an embedded system to execute constantly and so, an infinite loop can help you there.

Returning different values that 0 like, return 1 or return -1 can mean that function finished returning error. But this is not mandatory and it's just a way to evaluate the execution of a function. Anyway you can give it the meaning you need.

 

Best Regards and Happy Coding!

 

0 Kudos

372 Views
QJ_HAPPY
Contributor I
Thank you for your timely reply. I want to know why I will return - 1 error. Generally, 0 should not be returned if there is no error
0 Kudos