Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2008.05.11;
Скачать: CL | DM;

Вниз

const   Найти похожие ветки 

 
DFT   (2008-04-15 12:32) [0]

Уважаемые Мастера, подскажите пожалуйста!

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

(в коде VCL const при объявлении параметров процедур или функций, используется чаще с типом string, как мне показалось).

И в чем смысл такого, например, объевления процедуры:

Procedure Add(i: integer; const J: integer = 1);   ...?


 
Ega23 ©   (2008-04-15 12:34) [1]


A constant (const) parameter is like a local constant or read-only variable. Constant parameters are similar to value parameters, except that you can"t assign a value to a constant parameter within the body of a procedure or function, nor can you pass one as a var parameter to another routine. (But when you pass an object reference as a constant parameter, you can still modify the object"s properties.)

Using const allows the compiler to optimize code for structured- and string-type parameters. It also provides a safeguard against unintentionally passing a parameter by reference to another routine.

Here, for example, is the header for the CompareStr function in the SysUtils unit:

function CompareStr(const S1, S2: string): Integer;

Because S1 and S2 are not modified in the body of CompareStr, they can be declared as constant parameters.


 
DFT   (2008-04-15 12:43) [2]

Спасибо.


 
Ega23 ©   (2008-04-15 13:07) [3]


> DFT   (15.04.08 12:43) [2]
>
> Спасибо.


Незачто. Но в следующий раз, будь добр, посмотри справку сам, ОК?



Страницы: 1 вся ветка

Текущий архив: 2008.05.11;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.017 c
11-1188820984
Max727
2007-09-03 16:03
2008.05.11
KOLmdvXLGrid


2-1207902209
An software developer
2008-04-11 12:23
2008.05.11
Подскажите, правильно ли подавляются сообщения об ошибках?


15-1206636452
X9
2008-03-27 19:47
2008.05.11
WiFi на 4 км - реально ли?


15-1206533074
Тыщ
2008-03-26 15:04
2008.05.11
Ассемблер в Turbo Pascal 7.0


2-1208248370
DFT
2008-04-15 12:32
2008.05.11
const