Not
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012
The #defInc and #defDec directives apply only to macros that have a value that can be converted to the formal int type. A value can only contain numerals. The only non-numeric character allowed is a leading negative sign (-).
#defInc and #defDec are the only directives that interpret the value of a macro.
The integer value is treated as an X++ int, not as an int64.
Prerequisites
For this topic, you must understand the information in How to: Test a Macro Value.
Code Sample Using #defInc and #defDec
In the following code sample, the initial value of the macro CounterMacroA is a string that can be converted into an integer. The sample shows how the #defInc and #defDec directives can be used for this macro name.
static void SimpleDefINCJob(Args _args)
{
;
#define.CounterMacroA(1)
#defInc.CounterMacroA
info("mg11: # CounterMacroA == " + int2str(#CounterMacroA));
#if.CounterMacroA(2)
info("mg12: # if confirms CounterMacroA == 2");
#endif
#defDec.CounterMacroA
info("mg23: # CounterMacroA == " + int2str(#CounterMacroA));
#if.CounterMacroA(1)
info("mg24: # if confirms CounterMacroA == 1");
#endif
/************** Actual Infolog output
Message (12:47:57 pm)
mg11: # CounterMacroA == 2
mg12: # if confirms CounterMacroA == 2
mg23: # CounterMacroA == 1
mg24: # if confirms CounterMacroA == 1
**************/
}
Treatment of Special Values
It is recommended that the #defInc and #defDec directives only be used for macros that have an integer value. The precompiler follows special rules for #defInc when the macro value is not an integer, or when the value is unusual or extreme.
Values that are Converted to Zero
The following table lists the values that #defInc converts to zero (0) and then increments. When a value is converted to 0 by #defInc, the original value cannot be recovered, not even by #defDec.
Macro value |
Behavior |
|---|---|
(+55) |
The positive sign (+) prefix makes the precompiler treat this as a non-numeric string. The precompiler treats all non-numeric strings as 0 when it handles a #defInc (or #defDec) directive. |
("3") |
Integers enclosed in quotation marks are treated as 0. The quotation marks are discarded, and these changes persist. |
( ) |
A string of spaces is treated as 0, and then incremented. |
() |
A zero-length string is treated as 0, and then incremented, when the value is enclosed in parentheses, as in #define.MyMac(). |
(Random string.) |
Any non-numeric string of characters is treated as 0, and then incremented. |
(0x12) |
Hexadecimal numbers are treated as non-numeric strings. Therefore they are converted to 0, and then incremented. |
Other Special Values
The following table explains how other special values are treated by #defInc.
Macro value |
Behavior |
|---|---|
(-44) |
Negative numbers are acceptable, including integers without the negative sign (-). |
(2147483647) |
The maximum positive int value is changed to the minimum negative int value by #defInc. |
(999888777666555) |
Any large number, beyond the capacity of int and int64. This is treated as the maximum positive int value. |
(5.8) |
Real numbers are truncated by #defDec (and #defInc). Subsequent symbol substitution shows that the truncation persists. |
When no value and no parentheses are provided for the directive #define.MyValuelessMacro, the precompiler rejects use of the directive #defInc.MyValuelessMacro. |
Important Scoping of #defInc
For macro names that are used by the #defInc directive, it is important that the #define directive that creates the macro not reside in a class declaration. The behavior of #defInc in these cases is unpredictable. Instead, such macros should be defined in only a method or job.
See also
Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.