C Language main()

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

C Language main()

1,132 次查看
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 项奖励
回复
2 回复数

1,119 次查看
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 项奖励
回复

1,051 次查看
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 项奖励
回复