函数体Function Body

“函数体”是包含指定函数行为的语句的复合语句。A "function body" is a compound statement containing the statements that specify what the function does.

语法Syntax

function-definition:function-definition:
declaration-specifiers optattribute-seq optdeclarator declaration-list optcompound-statementdeclaration-specifiers optattribute-seq optdeclarator declaration-list optcompound-statement

/* attribute-seq 为 Microsoft 专用 //* *attribute-seq is Microsoft Specific */

compound-statement:/* 函数体 */compound-statement: /* The function body */
{ declaration-list optstatement-list opt}{ declaration-list optstatement-list opt}

在函数体中声明的变量“局部变量”具有 auto 存储类,除非另行指定。Variables declared in a function body, "local variables," have auto storage class unless otherwise specified. 调用函数时,将为局部变量创建存储并执行本地初始化。When the function is called, storage is created for the local variables and local initializations are performed. 执行控制权将传递给 compound-statement 中的第一个语句并继续传递,直到执行了 return 语句或到达函数体的末尾。Execution control passes to the first statement in compound-statement and continues until a return statement is executed or the end of the function body is encountered. 控制权随后返回到调用功能的点。Control then returns to the point at which the function was called.

如果该函数返回了值,则必须执行包含表达式的 return 语句。A return statement containing an expression must be executed if the function is to return a value. 如果没有执行 return 语句或 return 语句不包含表达式,则函数的返回值是不确定的。The return value of a function is undefined if no return statement is executed or if the return statement does not include an expression.

另请参阅See Also

C 函数定义C Function Definitions