Предварительное объявление |
- Statistics
- Participants
- Translate into Russian
- Translation result
- Translated in draft, editing and proof-reading required. Completed: 99%.
If you do not want to register an account, you can sign in with OpenID.
Forward declaration | ||
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. | Предварительное объявление является таким типом объявления, при котором компилятор имеет возможность разрешить ссылки из различных частей программы. Предварительное объявление позволяет программисту ссылаться на объекты, о которых компилятор ещё не знает, но которые будут определены в процессе компиляции позже. | |
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). | В программировании предварительное объявление - это объявление идентификатора (типа, переменной или функции), для которого программист ещё не дал полного определения. Объявление идентификатора требуется компилятору для того, чтобы знать тип (размер) идентификатора, но не его значения (в случае переменных). | |
void printThisInteger(int); | ||
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 в остальной части программы. Определение функции должно быть описано где-то ещё (в том же или другом файле; задача линкера - сопоставить ссылки на данную функцию в одном или нескольких объектных файлах с её единственным определением в другом): | |
void printThisInteger(int x) { | ||
printf("%d\n", x); | ||
} | ||
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: | |
int foo; //foo might be defined somewhere in this file | ||
extern int bar; //bar must be defined in some other file | extern int bar; //bar должно быть определено в другом файле | |
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: | В Паскале и других виртовских языках программирования тот факт, что все сущности должны быть объявлены до первого использования - общее правило. В языке Си применяется то же правило, делая исключения для необъявленных функций и неполных типов. Так, в Си есть возможность реализации пары взаимно-рекурсивных функций: | |
int first(int x) { | ||
if (x == 0) |
