Изменения

Материал из Chaotic Onyx
Перейти к навигацииПерейти к поиску
1516 байт добавлено ,  11:31, 14 ноября 2015
Строка 62: Строка 62:  
<!--The name of the macro may consist of upper and lowercase letters as well as digits and the underscore, as long as the first character is not a digit. By convention, macros are often named in all uppercase, but this is not a requirement.-->
 
<!--The name of the macro may consist of upper and lowercase letters as well as digits and the underscore, as long as the first character is not a digit. By convention, macros are often named in all uppercase, but this is not a requirement.-->
   −
It is also possible to have the macro take arguments which may then be substituted into the replacement text as desired.
+
Также можно придавать макросу значения аргументов, для более точного применения их в коде:
 +
<!--It is also possible to have the macro take arguments which may then be substituted into the replacement text as desired.-->
    
#define Name(Arg1,Arg2,...) Value
 
#define Name(Arg1,Arg2,...) Value
Arg1 is the name of the first argument.
+
Arg1 - название первого аргумента.
Arg2 is the name of the second argument, etc.
+
Arg2 - название второго аргумента, и т.д.
Wherever the argument names appear in the replacement text, they will be replaced by the values passed to the macro when it is used. Such a macro can be used like a procedure, but since it operates at the textual level, it is possible to do things which would not be possible with a procedure.
+
Перечисляемые аргументы будут найдены в коде, и им будет подставлено значение(value) данного макроса. Считается что это процедурный уровень, но так как он оперирует текстовыми значениями, его возможности более обширны и гибки.
 +
<!--Wherever the argument names appear in the replacement text, they will be replaced by the values passed to the macro when it is used. Such a macro can be used like a procedure, but since it operates at the textual level, it is possible to do things which would not be possible with a procedure.-->
   −
Care should be taken when using macros in expressions. Since the macro substitution simply inserts text from one place into another there is no guarantee that expressions within the macro will be evaluated before being combined with an outer expression. To be safe, you can put parenthesis around macro expressions to ensure they do not get combined in some unforeseen way with the external code.
+
Использовать макросы в выражениях следует с осторожностью - компилятор может не успеть посчитать вставленный из макроса текст, особенно в сочетании с другими текстовыми значениями кода. Для безопасности вы можете взять значения макроса в круглые скобки #define Macro (Value) - чтобы значение не пересекалось с другим исполняемым кодом.
 +
<!--Care should be taken when using macros in expressions. Since the macro substitution simply inserts text from one place into another there is no guarantee that expressions within the macro will be evaluated before being combined with an outer expression. To be safe, you can put parenthesis around macro expressions to ensure they do not get combined in some unforeseen way with the external code.-->
   −
The following code, for example, uses this technique to prevent the bitshift operator << from taking a lower order of operations when the macro is used in some larger expression.
+
Вот пример кода, применяемый для решения проблем с оператором сдвигом разряда << ,без затрагивания остальной части кода после вставления макроса.
 +
<!--The following code, for example, uses this technique to prevent the bitshift operator << from taking a lower order of operations when the macro is used in some larger expression.-->
    
#define FLAG1 (1<<0)
 
#define FLAG1 (1<<0)
470

правок

Навигация