POV-Ray : Newsgroups : povray.bugreports : #if/#else/#end in nested macros--*possible* problem? : #if/#else/#end in nested macros--*possible* problem? Server Time
15 May 2024 17:23:23 EDT (-0400)
  #if/#else/#end in nested macros--*possible* problem?  
From: Kenneth
Date: 9 Sep 2009 11:35:00
Message: <web.4aa7ca00e97b83e6f50167bc0@news.povray.org>
Concerns v3.6.1c (sorry, I'm working on an elaborate animation and don't want to
switch to the newer version until everything's done and rendered.)

I've lately come across a 'situation' in using nested macros--all containing #if
blocks--causing a hard-to-pinpoint error.  (I can't say for sure what the
'problem' actually is, because my code is so complex that it's difficult to
construct some meaningful test code.)  Essentially, I'm curious about
something: Is it *possible* that macros-within-macros, each using #if
blocks--some WITH an #else statement and some without--might create a problem
for POV's core code trying to determine which #else statement to use for which
macro? Here's a very simplistic example of what I mean:

#macro my_macro_1()
 #if (*something is true*)
 --#local *do something*--
 // #else// left out, not specifically needed for code. #if does nothing.
 #end
#end

#macro my_macro_2()
  #if(*something else is true)
  my_macro_1()
  #else // an ACTUAL #else
  --#local *do something else*
  #end
#end

#macro my_macro_3()
  #if(*something different is true)
  my_macro_2() // contains macros 1 and 2
  // #else // again left out, not needed. #if does nothing.
  #end
#end

Then invoking the third macro:
my_macro_3()


In macros 1 and 3, the #else statement is left out in the macros' #if blocks
(but implied to be there, according to docs.) I'm aware that macros using
#locals invoke the 'most immediate' use of variables. But I'm wondering about
the 'implied' #else statements-- if, somehow, POV could perhaps be mistakenly
using macro 2's REAL #else in macros 1 or 3 (depending on which of the three
#if's is true or false.) OR, vice versa--the 'invisible' #else in  macros 1 and
3 affecting macro 2. I'm sorry I can't be more exact as to a test-code scene;
this simple example may not even be appropriate. (My own real code has far more
complex macros.)

What prompts my question is that the problem in my own code *seems* to have been
solved by going back and adding ALL of the #else terms to the macros, even
though some were not actually needed.  (And I've since taken to doing this as a
'safety measure' in all my scenes.) But right now, this 'solution' is kind of a
mystery to me, not knowing if it's really necessary. There could be something
else wrong with my code (although I've gone over it in detail, looking for
mistakes)--in which case I simply stumbled onto a 'workable' solution that
didn't solve the real problem!

Ken


Post a reply to this message

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