Предварительное объявление

http://en.wikipedia.org/w/index.php?title=Forward_declaration&action=history, “Forward declaration”, public translation into Russian from English More about this translation.

See also 47 similar translations

Translate into another language.

Participants

RusCloud499 points
insolor4 points
Join Translated.by to translate! If you already have a Translated.by account, please sign in.
If you do not want to register an account, you can sign in with OpenID.
Pages: ← previous Ctrl next next untranslated
1 2

Forward declaration

Предварительное объявление

History of edits (Latest: RusCloud 6 months ago) §

A Forward declaration is a type of declaration which enables the compiler to resolve references from different parts of a program. The purpose being to allow a programmer to refer to objects that the compiler may not yet have met but that will be defined later in the compilation process.

Предварительное объявление является таким типом объявления, при котором компилятор имеет возможность разрешить ссылки из различных частей программы. Предварительное объявление позволяет программисту ссылаться на объекты, о которых компилятор ещё не знает, но которые будут определены в процессе компиляции позже.

History of edits (Latest: RusCloud 6 months ago) §

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. It is required for a compiler to know the type (size) of an identifier, but not a particular value it holds (in case of variables).

В программировании предварительное объявление - это объявление идентификатора (типа, переменной или функции), для которого программист ещё не дал полного определения. Объявление идентификатора требуется компилятору для того, чтобы знать тип (размер) идентификатора, но не его значения (в случае переменных).

History of edits (Latest: RusCloud 6 months ago) §

void printThisInteger(int);

void printThisInteger(int);

History of edits (Latest: RusCloud 6 months ago) §

In C/C++, the line above represents forward declaration of a function and is the function's prototype. After processing this declaration, the compiler would allow the programmer to refer to the entity printThisInteger in the rest of the program. Definition for a function must be provided somewhere (same file or other, where it would be responsibility of the linker to correctly match references to particular function in one or several object files with its definition, which must be unique, in another):

В C/C++, приведённая строка означает предварительное объявление функции и является её прототипом. После обработки этого объявления, компилятор даёт возможность программисту ссылаться на сущность printThisInteger в остальной части программы. Определение функции должно быть описано где-то ещё (в том же или другом файле; задача линкера - сопоставить ссылки на данную функцию в одном или нескольких объектных файлах с её единственным определением в другом):

History of edits (Latest: RusCloud 6 months ago) §

void printThisInteger(int x) {

void printThisInteger(int x) {

History of edits (Latest: RusCloud 6 months ago) §

printf("%d\n", x);

printf("%d\n", x);

History of edits (Latest: RusCloud 6 months ago) §

}

}

History of edits (Latest: RusCloud 6 months ago) §

Variables may have only forward declaration and lack definition. During compilation time these are initialized by language specific rules (to undefined values, 0, NULL pointers, ...). Variables, which are defined in other source/object file, must have a forward declaration specified with a keyword extern:

Переменные могут быть объявлены и не определены. Такие переменные процессе компиляции инициализируются согласно правилам языка (неопределенным значением, нулём, NULL-указателем, ...). Переменные, имеющие определение в другом исходном/объектном файле, должны быть предварительно объявлены с ключевым словом extern:

History of edits (Latest: RusCloud 6 months ago) §

int foo; //foo might be defined somewhere in this file

int foo; //foo могло быть определено где-то в этом файле

History of edits (Latest: RusCloud 6 months ago) §

extern int bar; //bar must be defined in some other file

extern int bar; //bar должно быть определено в другом файле

History of edits (Latest: RusCloud 6 months ago) §

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 and incomplete types. Thus, in C it is possible (although unwise) to implement a pair of mutually recursive functions thus:

В Паскале и других виртовских языках программирования тот факт, что все сущности должны быть объявлены до первого использования - общее правило. В языке Си применяется то же правило, делая исключения для необъявленных функций и неполных типов. Так, в Си есть возможность реализации пары взаимно-рекурсивных функций:

History of edits (Latest: RusCloud 6 months ago) §

int first(int x) {

int first(int x) {

History of edits (Latest: RusCloud 6 months ago) §

if (x == 0)

if (x == 0)

History of edits (Latest: RusCloud 6 months ago) §
Pages: ← previous Ctrl next next untranslated
1 2