In computer programming, a forward declaration is a declaration of an identifier (denoting an entity such as a type, a variable, or a function) for which the programmer has not yet given a complete definition. struct person; int elements; void print(int); In C and C++, the three lines above represent forward declarations of a struct (which is a type), an array, and a function, respectively. (The latter takes one parameter and is the function's prototype.
| Property | Value |
| dbpprop:abstract
|
- In computer programming, a forward declaration is a declaration of an identifier (denoting an entity such as a type, a variable, or a function) for which the programmer has not yet given a complete definition. struct person; int elements; void print(int); In C and C++, the three lines above represent forward declarations of a struct (which is a type), an array, and a function, respectively. (The latter takes one parameter and is the function's prototype. ) After processing these declarations, the compiler would allow the programmer to refer to the entities person, elements and print in the rest of the program; but at some point the programmer would still have to provide definitions for the declared entities: struct person const char *name; char sex; int age; int elements[10]; void print(int x) printf("%d\n", x); In Pascal and other Wirth programming languages, it is a general rule that all entities must be declared before use. In C, the same general rule applies, but with an exception for undeclared functions. Thus, in C it is possible (although unwise) to implement a pair of mutually recursive functions thus: int first(int x) if (x == 0) return 1; return second(x-1); int second(int x) if (x == 0) return 0; return first(x-1); In Pascal, the same implementation requires a forward declaration of second to precede its use in first. Without the forward declaration, the compiler will produce an error message indicating that the identifier second has been used without being declared.
- プログラミングにおいて、前方宣言とはプログラマが完全な定義を与えていない変数または関数の宣言のことである。 int elements; void foo(int); C言語では、上の二つの行はそれぞれ 配列 と 一つの引数の関数 の前方宣言を表す。コンパイラはこれらの宣言を処理した後、プログラマに残りの部分でelementsとfooの実体の使用を許可する。しかしいくつかの場合、プログラマは宣言した実体のための定義を提供しなければならないだろう: int elements[10]; void foo(int x) printf("%d\n", x); Pascalや他のヴィルトの言語では、前方宣言は使う前にすべての実体を宣言しなければならないという一般的規則である。C言語でも同じ一般的規則が適用されるが、未宣言の関数のための例外がある。その結果、C言語では(賢明ではないが)相互再帰の関数ペアを実行することが可能である: int first(int x) if (x == 0) return 1; return second(x-1); int second(int x) if (x == 0) return 0; return first(x-1); Pascalで同様の実装をする場合、firstがsecondを呼び出す前にsecondの前方宣言が必要である。前方宣言がなければ、コンパイラは識別子 secondが宣言されないで使われたというエラーメッセージを表示するであろう。
|
| dbpprop:hasPhotoCollection
| |
| dbpprop:reference
| |
| rdf:type
| |
| rdfs:comment
|
- In computer programming, a forward declaration is a declaration of an identifier (denoting an entity such as a type, a variable, or a function) for which the programmer has not yet given a complete definition. struct person; int elements; void print(int); In C and C++, the three lines above represent forward declarations of a struct (which is a type), an array, and a function, respectively. (The latter takes one parameter and is the function's prototype.
|
| rdfs:label
| |
| owl:sameAs
| |
| skos:subject
| |
| foaf:page
| |
| is dbpprop:redirect
of | |
| is owl:sameAs
of | |