开发者

What are the names used to describe the "top" and "bottom" portions of a C-style function definition?

I am looking for a name or phrase to identify two distinct parts of a f开发者_JAVA百科unction definition

1. The part that looks exactly the same as the function declaration (minus the semi-colon)

2. The rest (the portion within and including the curly-braces)

int someFunction(int value, bool flag)  // part one
{ ... }                                 // part two

Is there an accepted way to describe these two parts?


I call them the function header and function body. A quick glance at Harbison & Steele comes up with no real names for them.


I'd use prototype and body. Body is use widely for that purpose, prototype has formally a slightly different meaning.

Edit: The standard use function declarator (sometimes abbreviated to declarator) and body. For instance in 6.9.1/13 which is an example stating

In the following:

extern int max(int a, int b)
{
    return a > b ? a : b;
}

extern is the storage-class specifier and int is the type specifier; max(int a, int b) is the function declarator; and { return a > b ? a : b; } is the function body.


main has no prototype -- so says the Standard -- and I kinda dislike header.

So I call them 'function signature' and 'function body'.


Here's an interesting tidbit on it... http://msdn.microsoft.com/en-us/library/w3sez2yb.aspx

part one can be the function prototype, part two is called the function body.


Functions have the function prototype declaration, definition, and body.

void SomeFunction(void);  //Prototype declaration.

void SomeFunction(void) /*Function Definition*/ { /*Function Body*/ }


Here's the grammar for a function definition:

function-definition:
    declaration-specifiers declarator declaration-listopt compound-statement

Normally I don't really distinguish between the two. If pressed, I'd use "body" for the {...} portion, and either "signature" or "prototype" for the rest.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜