POV-Ray : Newsgroups : povray.advanced-users : macro argument / output / variable question : Re: macro argument / output / variable question Server Time
25 Apr 2024 18:32:36 EDT (-0400)
  Re: macro argument / output / variable question  
From: Bald Eagle
Date: 17 Jul 2017 07:55:00
Message: <web.596ca51ae1619e6cc437ac910@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:

I always thought that the value of OneVariable would get copied to X, and
Another would get copied to Y, and the macro would operate on X and Y, not
OneVariable and Another.  So I would have always tried to output any values from
the macro via
#declare A = macro ThisMacro (A)

But apparently X and Y are just pointers / links / containers for the REAL
variables, and when I perform operations on X and Y, the underlying actual
variables that get passed into the macro get changed.


.... and indeed after running the below, it works just like that.
Good to know!  That will help with a lot of debugging.

[X] Learned something new today

#macro SwapXY (X, Y)
 // Input/output: X, Y
 // On output, the values of X and Y have been interchanged.
 #local Z = X; // Z is a placeholder variable
 #local X = Y;
 #local Y = Z;
#end

#declare A = 1;
#declare B = 2;

#debug concat ( "A = ", str (A, 3, 1), "B = ", str (B, 3, 1), "\n")

SwapXY (A, B)

#debug concat ( "A = ", str (A, 3, 1), "B = ", str (B, 3, 1), "\n")


Post a reply to this message

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