函数
函数头注释
/************************************************************************
* Function Name : nucFindThread 函数名
* Create Date : 2000/01/07 创建日期
* Author/Corporation : your name/your company name 作者
*
* Description : Find a proper thread in thread array. 描述
* If it’s a new then search an empty.
*
* Param : ThreadNo: someParam description 参数
* ThreadStatus: someParam description
*
* Return Code : Return Code description,eg: 返回值
ERROR_Fail: not find a thread
ERROR_SUCCEED: found
*
* Global Variable : DISP_wuiSegmentAppID
* File Static Variable : naucThreadNo
* Function Static Variable : None
*
*------------------------------------------------------------------------
* Revision History 版本信息
* No. Date Revised by Item Description
* V0.5 2008/01/07 your name … …
************************************************************************/
static unsigned char nucFindThread(unsigned char ThreadNo,unsigned char ThreadStatus)
{
…
}
复杂的函数中,在分支语句,循环语句结束之后需要适当的注释,方便区分各分支或循环体。
while (condition)
{
statement1;
if (condition)
{
for(condition)
{
Statement2;
}//end 'for(condition)'
}
else
{
statement3;
}//'end if (condition)'
statement4
}//end 'while (condition)'
修改别人代码的时候不要轻易删除别人的代码,应该用适当的注释方式
while (condition)
{
statement1;
//
//your name , 2008/01/07 delete
//if (condition)
//{
// for(condition)
// {
// Statement2;
// }
//}
//else
//{
// statement3;
//}
///
// your name , 2000/01/07 add
…
new code
…
///
statement4
}
递归函数的展开
平时写代码,不到万不得已,尽量不要用递归。
即便是要用递归,也要注意递归的层次不要太深,防止出现栈溢出的错误;
同时递归的停止条件一定要正确,否则,递归可能没完没了。
void fun(int i)
{
if (i>0)
{
fun(i/2);
}
printf("%d\n",i);
}
int main()
{
fun(10);
return 0;
}
// 输出:
// 0
// 1
// 2
// 5
// 10
// 递归函数展开 =====================
void fun(int i)
{
if (i>0)
{
//fun(i/2);
if(i/2>0)
{
if(i/4>0)
{
if(i/8>0)
{
if(i/16>0)
{
... // 不执行
}
printf("%d\n",i/16); // 0
}
printf("%d\n",i/8);// 1
}
printf("%d\n",i/4); // 2
}
printf("%d\n",i/2); // 5
}
printf("%d\n",i);// 10
}
文件结构
文件头
/************************************************************************
* File Name : FN_FileName.c/ FN_FileName.h 文件名
* Copyright : 2003-2008 XXXX Corporation,All Rights Reserved. 版权亦称“著作权”
* Module Name : Draw Engine/Display 文件模块功能名称
*
* CPU : ARM7
* RTOS : Tron
*
* Create Date : 2008/10/01 创建日期
* Author/Corporation : WhoAmI/your company name 作者
*
* Abstract Description : Place some description here. 文件描述信息
*
*-----------------------Revision History----------------------- 版本信息
* No Version Date Revised By Item Description
* 1 V0.95 08.05.18 WhoAmI abcdefghijklm WhatUDo
*
************************************************************************/