POV-Ray : Newsgroups : povray.advanced-users : problem using ORs and strcmp() in #switch/#case : Re: problem using ORs and strcmp() in #switch/#case Server Time
29 Apr 2024 08:12:08 EDT (-0400)
  Re: problem using ORs and strcmp() in #switch/#case  
From: Kenneth
Date: 8 Nov 2017 12:25:02
Message: <web.5a033a451346e9e089df8d30@news.povray.org>
Kenneth wrote...
> #switch(0)
> #case(strcmp(IMG_TYPE,AA)=0)
>
> I ask because the latter doesn't work--no error message of any kind is created,
> but it falls through to the #else clause, even though strcmp(IMG_TYPE,AA) is a
> 'match' between IMG_TYPE and AA.

Bald Eagle wrote...
> Which means that it evaluates to TRUE, or 1, which is NOT 0.

> Stop thinking in terms of conditional Boolean word results, and think in 0 or 1.

> #if (strcmp(IMG_TYPE,AA)=0)
> would give a Boolean result of 1.

And Clipka wrote...
> If IMG_TYPE is equal to AA, then `strcmp(IMG_TYPE,AA)` will yield 0.
> Comparing that result with zero will yield true, i.e. some non-zero number.

Ah! OK, this finally makes sense to me! Thanks to you both. (All of this stuff
reminds me of my college days, when I struggled mightily to grasp the
complexities of Boolean operations. Ugh. It made my brain hurt then too.)

Kenneth wrote...
> I didn't know that using #cases without #breaks was possible :-O  Thanks!
> ...a note in the documentation about it would be justified ;-)

Clipka...
> It's hinted at very briefly in the v3.7 docs.

Oops, you're right (as I see after re-reading the docs for the 137-th
time...ha...)

"If a clause evaluates true but no #break is specified, the parsing will fall
through to the next #case or #range and that clause conditional is evaluated."

So apparently it also works if a clause evaluates 'false' (the pseudo-OR
behavior.)


Post a reply to this message

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