POV-Ray : Newsgroups : povray.beta-test : Optional macro parameters : Re: Optional macro parameters Server Time
25 Apr 2024 06:24:13 EDT (-0400)
  Re: Optional macro parameters  
From: clipka
Date: 24 Mar 2017 17:12:34
Message: <58d58bc2$1@news.povray.org>
Am 24.03.2017 um 12:33 schrieb Bald Eagle:
> #macro Test (optional A, optional B, optional C, optional D)
>  #debug "Start macro Test \n"
>  #ifndef (local.A)
>   #debug "No parameters defined \n"
>  #end

That test isn't really accurate. `#ifndef(local.A)` only tells you
whether the first parameter was omitted; parameters B, C and/or D might
still be supplied, as in:

    Test(,2,3,4)

Note that POV-Ray's optinal parameters differ from those in C/C++ in
that you can declare _any_ parameter as optional, not just the last
ones. For example, in

    #macro Test(optional A, B, C, D)
    #end

only parameter A is optional, the others are mandatory.

Also, POV-Ray allows you to pass undefined variables to optional
parameters, e.g.:

    #undef Blah
    Test(Blah,2,3,4)


>  #ifdef (local.A)
>   #macro _Test (A, B, optional C, optional D)
> 
>   #end // end macro _Test
>  #end
>  #debug "End macro Test \n"
> #end // end macro Test

Defining a macro inside a macro? That's... uh... yeah, /possible/, I guess.


> With Test (1, 2) I get "expected 4 but only found 2", or
> 
> with Test (1, 2)
> "expected 8 but only found 2"

That statement of yours doesn't make sense.


Post a reply to this message

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