POV-Ray : Newsgroups : povray.bugreports : #if/#else/#end in nested macros--*possible* problem? : Re: #if/#else/#end in nested macros--*possible* problem? Server Time
15 May 2024 14:06:01 EDT (-0400)
  Re: #if/#else/#end in nested macros--*possible* problem?  
From: clipka
Date: 9 Sep 2009 12:24:30
Message: <4aa7d6be$1@news.povray.org>
Kenneth schrieb:
> 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?

No, unless there would be a serious bug somewhere in there.

Such things can happen in languages where the if statement does not 
necessarily open a statement block, but can be followed by a single 
statement, and the else clause is optional, as in C, allowing for the 
syntax variants

     if (CONDITION) STATEMENT
     if (CONDITION) STATEMENT else STATEMENT

as shorthand for

     if (CONDITION) { STATEMENT }
     if (CONDITION) { STATEMENT } else { STATEMENT }

causing ambiguity whenever the shorthand form is used in nested if 
constructs with some else clause being omitted:

     if (CONDITION) if (CONDITION) STATEMENT else STATEMENT

By definition the else is then attributed to the last if, which may or 
may not be the intended behavior.

However, this cannot happen in POV-Ray, as each #if statement must 
always be matched by an #end, so there is never any ambiguity which #if 
an #else belongs to.

You can still confuse the parser by forgetting the #end for an #if, but 
in this case the parser will notice that something is bogus:

     #if (foo)
         #if (bar)
             execute_if_foo_and_bar()
         /* #end forgotten here */
     #else
         execute_if_not_foo()
     #end
     /* parser will complain about a missing #end here */

As #end is also used to terminate macros, there's also no way to define 
partial #if statements in a macro.


Post a reply to this message

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