|
|
On 6/28/24 01:13, ingo wrote:
> William F Pokorny <ano### [at] anonymousorg> wrote:
>
>
> #macro Add(_immuInt, otherInt)
> ......
> #end
>
> #declare Res = Add(99,1)
>
> #declare _immu = 99;
>
> #declare Res = Add(_immu, 1)
>
> In the second use of the macro, would it be required that the 'referenced' value
> is also declared immutable?
>
> ingo
>
If I'm understanding you, no with respect to the macro, identifier pass
by reference issue.
As long as you have _immuInt as the first macro Add() parameter name,
the call can be Add(_immu,1) or Add(Res,1) and neither _immu or Res can
be changed by any #local or #declare use of _immuInt inside the macro.
That said, the Res identifier is not protected from someone writing:
#declare Res = 42;
inside the macro while
#declare _immu = 42;
will be illegal inside the Add() macro. So, it's not necessary the _
prefix immutability be indicated in both the macro parameter and more
global calling space - but it is a good idea, if you want protection
from someone making more global changes from within the macro.
Related. The hole in the prefix based constant-ness is that it is NOT
propagated into macros called. For example,
#macro Add(V1,V2)
#local V1 = V1+V2;
V1
#end
#declare _immu = 42;
#declare Val99 = Add(_immu,1);
will still result in the _immu getting clobbered. The best practice
would be to always use macro parameter names with the _ prefix - unless
you are truly aiming to change identifiers by reference inside the
macro.
Bill P.
Post a reply to this message
|
|