POV-Ray : Newsgroups : povray.advanced-users : macro argument / output / variable question : Re: macro argument / output / variable question Server Time
26 Apr 2024 07:38:27 EDT (-0400)
  Re: macro argument / output / variable question  
From: clipka
Date: 16 Jul 2017 16:05:55
Message: <596bc723$1@news.povray.org>
Am 14.07.2017 um 20:38 schrieb Bald Eagle:

> #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
> 
> My question is, does a mechanism exist by which the true identities of the
> variable names passed to the macro can be accessed?
> Such that if I do:
> #macro SwapXY (OneVariable, Another)
> 
> it will actually redefine THOSE variables?

Whenever you pass a variable name as a macro parameter, that macro
parameter will actually behave as a reference to that variable. So the
macro above would indeed work.

The variable name must be defined beforehand though, and the macro can't
undefine it; so the following will fail:

    #declare A = 1;
    // leave B undefined.
    Swap(A,B)


Post a reply to this message

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