POV-Ray : Newsgroups : povray.general : Macro return value on failure : Re: Macro return value on failure Server Time
23 Apr 2024 05:59:46 EDT (-0400)
  Re: Macro return value on failure  
From: clipka
Date: 24 Jul 2018 04:09:26
Message: <5b56deb6$1@news.povray.org>
Am 24.07.2018 um 00:49 schrieb Mike Horvath:

> Wow, I thought local variables only worked in the local scope. E.g. the
> globally declared variable in the code you supplied would retain its
> original value.

For clarification - what JimT is describing is the following behaviour:


    #macro Foo(A)
      #local A = 42;
    #end

    #declare A = 1; // just for clarification
    #declare X = 1;
    Foo(X)
    #debug concat("A = ",str(A,0,0),"\n") // still 1
    #debug concat("X = ",str(X,0,0),"\n") // now 42


So `#local A` in a macro does not change the global variable named `A`.
It does, however, change the macro parameter named `A`. If a global
variable happens to be passed to that macro parameter, that global
variable (no matter what its name outside the macro) is also changed.

This call-by-reference behaviour is intentional, as a means to pass
additional information back out of a macro.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.