POV-Ray : Newsgroups : povray.general : #ifdef using a string expression? Server Time
23 Nov 2026 19:01:19 EST (-0500)
  #ifdef using a string expression? (Message 1 to 38 of 38)  
From: Kenneth
Subject: #ifdef using a string expression?
Date: 14 Mar 2023 08:45:00
Message: <web.64106b86bf01f0119b4924336e066e29@news.povray.org>
(v3.8.0 beta 1 in Windows 10)

I was playing around with #ifdef recently; just experimenting.

I put a nonsense string expression into it-- not actually defined anywhere-- to
see what would happen:

#ifdef("htenneK")
....do this...
#else
....do that...
#end

Instead of issuing an error message or even a fatal error as I half-way
expected, it actually fell through to the *first* clause successfully. Without
the double quotes, it works as expected and falls through to the #else.

Should #ifdef behave this way? Is the first double-quote causing some kind of
unforeseen problem for the parser?


Post a reply to this message

From: Alain Martel
Subject: Re: #ifdef using a string expression?
Date: 14 Mar 2023 08:54:05
Message: <64106e6d@news.povray.org>
Le 2023-03-14 à 08:43, Kenneth a écrit :
> (v3.8.0 beta 1 in Windows 10)
> 
> I was playing around with #ifdef recently; just experimenting.
> 
> I put a nonsense string expression into it-- not actually defined anywhere-- to
> see what would happen:
> 
> #ifdef("htenneK")
> ....do this...
> #else
> ....do that...
> #end
> 
> Instead of issuing an error message or even a fatal error as I half-way
> expected, it actually fell through to the *first* clause successfully. Without
> the double quotes, it works as expected and falls through to the #else.
> 
> Should #ifdef behave this way? Is the first double-quote causing some kind of
> unforeseen problem for the parser?
> 
> 
> 
> 
As I see it, #ifdef() test the existence of an entity.
With the quotes, the string DO exist, IS defined, even if it only exist 
locally. So, the test returns true.
Without the quotes, it test if the variable exist, and, if it wasn't 
#declare beforehand, will return false.

So, I think that it behave as it should.


Post a reply to this message

From: jr
Subject: Re: #ifdef using a string expression?
Date: 14 Mar 2023 09:25:00
Message: <web.6410757998df09c94301edef6cde94f1@news.povray.org>
hi,

Alain Martel <kua### [at] videotronca> wrote:
> Le 2023-03-14 ΰ 08:43, Kenneth a ιcrit :
> > I was playing around with #ifdef recently; just experimenting.
> >
> > I put a nonsense string expression into it-- not actually defined anywhere-- to
> > see what would happen:
> >
> > #ifdef("htenneK")
> > ...
> As I see it, #ifdef() test the existence of an entity.
> With the quotes, the string DO exist, IS defined, even if it only exist
> locally. So, the test returns true.
> Without the quotes, it test if the variable exist, and, if it wasn't
> #declare beforehand, will return false.
>
> So, I think that it behave as it should.

agree, ref: <https://wiki.povray.org/content/Reference:Strings#String_Literals>


regards, jr.


Post a reply to this message

From: Kenneth
Subject: Re: #ifdef using a string expression?
Date: 18 Mar 2023 09:05:00
Message: <web.6415b5b098df09c99b4924336e066e29@news.povray.org>
Alain Martel <kua### [at] videotronca> wrote:
> >
> As I see it, #ifdef() test the existence of an entity.
> With the quotes, the string DO exist, IS defined, even if it only exist
> locally. So, the test returns true...
>
> So, I think that it behave as it should.

Sorry for the delay in responding; I had to think about this behavior for
awhile.

I guess it must certainly be so, and I sort of sense the logic of it...but it
does seem odd: The string expression is considered to have been created WITHIN
the #ifdef() itself? What seems strange to me is that #ifdef is not the same
'kind' of code construct as a #declare or #local, which would otherwise be
required earlier for any other kind of entity or variable for #ifdef to operate
on. Although, a string expression is not really a 'variable'; here, it exists as
a 'literal'. Yet a 'naked' string literal cannot be used by itself as a line of
code; that produces an obvious fatal error.

So is a string expression the only kind of 'thing' that #ifdef sees as defined?
Nope. Even an arbitrary float value behaves the same way:

#ifdef(7.6)
...do this... // success
#else
...do that...
#end

To me, this would seem to be an unexpected trap, waiting to be 'exploited' by
mistake. I'm not sure how such a mistake might be made by a user, but still...

My two-cents ;-)


Post a reply to this message

From: Bald Eagle
Subject: Re: #ifdef using a string expression?
Date: 18 Mar 2023 10:15:00
Message: <web.6415c75c98df09c91f9dae3025979125@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:

> The string expression is considered to have been created WITHIN
> the #ifdef() itself?

Well, it's defined by you, and the parser, and yes, once the parser hits that
closing ", then it's defined, and at that point, when the closing ) of the if
def gets hit - the conditions for TRUE are satisfied.

> What seems strange to me is that #ifdef is not the same
> 'kind' of code construct as a #declare or #local, which would otherwise be
> required earlier for any other kind of entity or variable for #ifdef to operate
> on.


> Although, a string expression is not really a 'variable'; here, it exists as
> a 'literal'. Yet a 'naked' string literal cannot be used by itself as a line of
> code; that produces an obvious fatal error.

But you're not declaring the value of a variable to be the string literal, any
more than you're using a direct string literal in text {} or str {} or any other
operator.



>
> So is a string expression the only kind of 'thing' that #ifdef sees as defined?
> Nope. Even an arbitrary float value behaves the same way:
>
> #ifdef(7.6)
> ...do this... // success
> #else
> ...do that...
> #end
>
> To me, this would seem to be an unexpected trap, waiting to be 'exploited' by
> mistake. I'm not sure how such a mistake might be made by a user, but still...


This is the way POV-Ray works with "Boolean" values (and IIRC, so do other
computer languages) O is false, and any non-zero value is true.
Send the str value of true to debug and see what it is.  It's a common shorthand
to use 0 and 1 for t&f or the setting of "flags" in code.

I often (ab) use this tool/trick to save some typing when doing loops.  If I'm
starting a loop at zero, then all I have to do is #ifdef(loopVariable) instead
of #if (loopVariable > 0).   Stuff like that.

(And to head off your purely theoretical complaint, 7.6 IS a number, and so it
IS defined when that ) closes the #ifdef statement.
You might try that with 0 and see what happens, but remember that we have to
have SOME way of signifying certain states, and we don't have proper variable
type casting in POV-Ray, so we rely on numerical values to represent
"undefined"/"null", NaN, and likely others.
Since we also have 2 parsers, you're likely to find other "surprises" in the
function parser behaviour.  ;) )

Also keep in mind that some variables that _were_ declared, will not be any more
- such as temporary macro arguments, loop counters, #local variables in include
files, etc.

Other things might be defined, or have defined values other than what you
thought they were, depending on how they've gotten to the point in the code that
you're at.  jr and Cousin Ricky have correctly pointed out that you can pass
things into macro calls "by reference" rather than "by pointer".


http://news.povray.org/povray.advanced-users/message/%3C5a02fe60%241%40news.povray.org%3E/#%3C5a02fe60%241%40news.povra
y.org%3E


Simply having a short script that sent all the various test results to #debug
would be a good reference, esp for reminders/new users (and testing new
versions).


Post a reply to this message

From: William F Pokorny
Subject: Re: #ifdef using a string expression?
Date: 18 Mar 2023 10:19:31
Message: <6415c873$1@news.povray.org>
On 3/18/23 08:59, Kenneth wrote:
> So is a string expression the only kind of 'thing' that #ifdef sees as defined?
> Nope. Even an arbitrary float value behaves the same way:
> 
> #ifdef(7.6)
> ...do this... // success
> #else
> ...do that...
> #end
> 
> To me, this would seem to be an unexpected trap, waiting to be 'exploited' by
> mistake. I'm not sure how such a mistake might be made by a user, but still...
> 
> My two-cents πŸ˜‰

I agree with three-cents - and now we have five! :-)

I took a quick look just now and v3.7 works as expected in some quick 
testing in that only identifiers are OK - which I do believe is the intent.

So, I'd say this is another v3.8 beta 2 bug.

It's something with the changes in parsing, but it must have happened 
prior to Christoph's back off point for the v3.8 parser too.

Bill P.


Post a reply to this message

From: Kenneth
Subject: Re: #ifdef using a string expression?
Date: 18 Mar 2023 11:35:00
Message: <web.6415d8cb98df09c99b4924336e066e29@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:

> >
> > So is a string expression the only kind of 'thing' that #ifdef sees
> > as defined?
> > Nope. Even an arbitrary float value behaves the same way:
> >
> > #ifdef(7.6)
> > ...do this... // success
> > #else
> > ...do that...
> > #end
> >
> This is the way POV-Ray works with "Boolean" values (and IIRC, so do other
> computer languages) O is false, and any non-zero value is true.
> Send the str value of true to debug and see what it is.  It's a
> common shorthand to use 0 and 1 for t&f or the setting of "flags" in code.

Yep, I get that-- if the #ifdef is seeing it as boolean, that is. But here's a
weird thing (well, weird to me at this point of my fuzzy understanding):
        #ifdef(true)
is apparently seen as NOT defined, and falls through to the #else. Of course,
I'm not even sure if that construct makes any sense code-wise or syntax-wise.
>
>
> (And to head off your purely theoretical complaint, 7.6 IS a number, and so it
> IS defined when that ) closes the #ifdef statement.
> You might try that with 0 and see what happens...

Strangely(?), this has the same result as above: #ifdef(0) falls through to the
first clause. So maybe the 'boolean' explanation doesn't hold for #ifdef?


Post a reply to this message

From: Kenneth
Subject: Re: #ifdef using a string expression?
Date: 18 Mar 2023 11:40:00
Message: <web.6415db2998df09c99b4924336e066e29@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:

>
> Strangely(?), this has the same result as above: #ifdef(0) falls through to the
> first clause. So maybe the 'boolean' explanation doesn't hold for #ifdef?

oops, sorry---
"Strangely(?), this does NOT have the same result as above: #ifdef(0) falls
through to the first clause" (and so is seen as defined.)


Post a reply to this message

From: Bald Eagle
Subject: Re: #ifdef using a string expression?
Date: 18 Mar 2023 13:05:00
Message: <web.6415ee9498df09c91f9dae3025979125@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:

> Yep, I get that-- if the #ifdef is seeing it as boolean, that is. But here's a
> weird thing (well, weird to me at this point of my fuzzy understanding):
>         #ifdef(true)
> is apparently seen as NOT defined, and falls through to the #else. Of course,
> I'm not even sure if that construct makes any sense code-wise or syntax-wise.

And you get that to work without a warning?

My few test cases resulted in:


#ifdef ("String") returns true.
#ifdef (1) returns true.
#ifdef (0) returns true.
"C:\Users\Mini\Documents\POV-Ray\v3.8-beta\scenes\DefinedValues.pov" line 13:
Parse Warning: Tried to test whether a reserved keyword is defined. Test result
may not be what you expect, and may fundamentally differ in future
versions.
#ifdef (true) returns false.
#ifdef (tau) returns false.
#ifdef (pi) returns false.
#ifdef (pigment) returns false.
#ifdef (if) returns false.
"C:\Users\Mini\Documents\POV-Ray\v3.8-beta\scenes\DefinedValues.pov" line 15:
Parse Warning: Tried to test whether a reserved keyword is defined. Test result
may not be what you expect, and may fundamentally differ in future
versions.
"C:\Users\Mini\Documents\POV-Ray\v3.8-beta\scenes\DefinedValues.pov" line 17:
Parse Warning: Tried to test whether a reserved keyword is defined. Test result
may not be what you expect, and may fundamentally differ in future
versions.
"C:\Users\Mini\Documents\POV-Ray\v3.8-beta\scenes\DefinedValues.pov" line 19:
Parse Warning: Tried to test whether a reserved keyword is defined. Test result
may not be what you expect, and may fundamentally differ in future
versions.
"C:\Users\Mini\Documents\POV-Ray\v3.8-beta\scenes\DefinedValues.pov" line 21:
Parse Warning: Tried to test whether a reserved keyword is defined. Test result
may not be what you expect, and may fundamentally differ in future
versions.
-
"C:\Users\Mini\Documents\POV-Ray\v3.8-beta\scenes\DefinedValues.pov" line 32:

Note that, "Test result may not be what you expect...." because it's a keyword,
not a proper variable.

I also tried:

#ifdef (0a) #debug concat ("#ifdef (", "0a", ") returns true. \n") #else #debug
concat ("#ifdef (", "0a", ") returns false. \n") #end

and get "No matching ), undeclared identifier found instead."


Post a reply to this message

From: William F Pokorny
Subject: Re: #ifdef using a string expression?
Date: 18 Mar 2023 16:29:55
Message: <64161f43$1@news.povray.org>
On 3/18/23 10:19, William F Pokorny wrote:
>> To me, this would seem to be an unexpected trap, waiting to be 
>> 'exploited' by
>> mistake. I'm not sure how such a mistake might be made by a user, but 
>> still...
>>
>> My two-cents πŸ˜‰
> 
> I agree with three-cents - and now we have five! πŸ˜„
> 
> I took a quick look just now and v3.7 works as expected in some quick 
> testing in that only identifiers are OK - which I do believe is the intent.
> 
> So, I'd say this is another v3.8 beta 2 bug.
> 
> It's something with the changes in parsing, but it must have happened 
> prior to Christoph's back off point for the v3.8 parser too.

Alright.

A long time ago I created a bunch of statically linked(a) versions of 
POV-Ray going back through time. Anyhow. Used these to trace the 
introduction of the str/num OK in #ifdef test bug.

Bill P.

(a) - This the old timer's container alternative.

---

commit 58d51f4911dce5e9021c62b30983902b0aab8b04  str,num OK
Author: Christoph Lipka <c-l### [at] usersnoreplygithubcom>
Date:   Sun Mar 1 02:05:39 2015 +0100

     Fixed scrambled warning messages.


// There are only five commits between the one up top and the bottom
// one below. My BIG bet is on the following commit being the problem,
// but I don't have a static compile of it or the one prior to it to
// be sure.

commit a94c1ab61aeb2aa483aa3636736ff1e24ebd8b78
Author: Christoph Lipka <c-l### [at] usersnoreplygithubcom>
Date:   Sun Mar 1 02:03:14 2015 +0100

Implemented tuple extensions to #declare and #local.
...


commit 3f56c5fb8a54998067a217e54101c799756510b4  Complains.
Author: Christoph Lipka <c-l### [at] usersnoreplygithubcom>
Date:   Tue Feb 3 16:48:11 2015 +0100

     Fixed Unix build errors.

---


Post a reply to this message

From: Kenneth
Subject: Re: #ifdef using a string expression?
Date: 19 Mar 2023 09:45:00
Message: <web.641710d898df09c99b4924336e066e29@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Kenneth" <kdw### [at] gmailcom> wrote:
>
> > Yep, I get that-- if the #ifdef is seeing it as boolean, that is. But
> > here's a weird thing (well, weird to me at this point of my fuzzy
> > understanding):
> >         #ifdef(true)
> > is apparently seen as NOT defined, and falls through to the #else.
>
> And you get that to work without a warning?
>

I didn't think to look. But you're right, I get the same warning:
"Parse Warning: Tried to test whether a reserved keyword is defined..." etc.

So with a *properly*-working #ifdef instead of the current flaw in v3.8.0 beta 1
or 2 'official' versions, I'm still curious about something you mentioned: Is it
supposed to indeed be a simple boolean comparison? Or is it's operation more
complex than that?


Post a reply to this message

From: Bald Eagle
Subject: Re: #ifdef using a string expression?
Date: 19 Mar 2023 10:15:00
Message: <web.641717fa98df09c91f9dae3025979125@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:

> So with a *properly*-working #ifdef instead of the current flaw in v3.8.0 beta 1
> or 2 'official' versions, I'm still curious about something you mentioned: Is it
> supposed to indeed be a simple boolean comparison? Or is it's operation more
> complex than that?

Wellll.......
I suppose it depends upon what one wants the language to do or thinks it
properly "ought" to do...


One could argue that a keyword is, in some sense, "defined", and as the warning
message states, reserved.

My example (probably me reading the whole post in a haze) of 0 / 1 was really
for _#if_, not #ifdef.

I'm sure that "Real programmers" have a better take on this, and sounder reasons
than I could present.

Aside:
Rather than having to write a whole ifdef/else/end statement for every case I
wanted to test, I had the strong urge to write a macro and maybe use ParseString
to make it work, but we don't have a way to test for data type, isolate
keywords, or any of the tools to write that sort of "meta" code.


Post a reply to this message

From: Kenneth
Subject: Re: #ifdef using a string expression?
Date: 19 Mar 2023 10:15:00
Message: <web.641718bf98df09c99b4924336e066e29@news.povray.org>
William F Pokorny <ano### [at] anonymousorg> wrote:
>
> Alright.
>
> A long time ago I created a bunch of statically linked(a) versions of
> POV-Ray going back through time. Anyhow. Used these to trace the
> introduction of the str/num OK in #ifdef test bug.
> [clip]
> My BIG bet is on the following commit being the problem,
> but I don't have a static compile of it or the one prior to it to
> be sure.
>

Given the current mix of flaws, the use of a string literal still has me
scratching my head...
        #ifdef("...string...")

Alain's and JR's explanation of the expected behavior seems valid; but with a
properly-working #ifdef, should the comparison fail outright (fatal error)? Or
should it still be seen as defined? I'm mostly just curious ;-)


Post a reply to this message

From: Bald Eagle
Subject: Re: #ifdef using a string expression?
Date: 19 Mar 2023 10:45:00
Message: <web.64171f2898df09c91f9dae3025979125@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:

> Given the current mix of flaws, the use of a string literal still has me
> scratching my head...
>         #ifdef("...string...")
>
> Alain's and JR's explanation of the expected behavior seems valid; but with a
> properly-working #ifdef, should the comparison fail outright (fatal error)? Or
> should it still be seen as defined? I'm mostly just curious ;-)

One might suggest:
"Expected variable name, literal value found instead."

-or- "It is what is is." ;)




The correct answer for me has always been OPTIONS.

When everything gets locked into a one-right-answer only format, it usually just
creates new problems in the process of "solving" the old.

I was just reading some old threads concerning this type of thing, and the
degenerate triangle warning vs 0-length fatal error for cylinders was brought
up.

For some scenes it could be a critical thing to stop the render.   For others,
you might want to just ignore them all.  Usually these things are addressed by
the users with workarounds, but why not have a configuration file that states
how to handle these cases, an additional argument for the object instantiation
that provides for individual control, or an error-trapping mechanism (with error
code) that allows the user to write their own programmatic/logical solution
based on further testing and flow control, and allows the user to issue better
warnings that the cryptic ones currently hard-coded in source?


Post a reply to this message

From: William F Pokorny
Subject: Re: #ifdef using a string expression?
Date: 19 Mar 2023 16:30:35
Message: <641770eb$1@news.povray.org>
On 3/19/23 10:14, Kenneth wrote:
> William F Pokorny <ano### [at] anonymousorg> wrote:
>>
>> Alright.
>>
>> A long time ago I created a bunch of statically linked(a) versions of
>> POV-Ray going back through time. Anyhow. Used these to trace the
>> introduction of the str/num OK in #ifdef test bug.
>> [clip]
>> My BIG bet is on the following commit being the problem,
>> but I don't have a static compile of it or the one prior to it to
>> be sure.
>>
> 
> Given the current mix of flaws, the use of a string literal still has me
> scratching my head...
>          #ifdef("...string...")
> 
> Alain's and JR's explanation of the expected behavior seems valid; but with a
> properly-working #ifdef, should the comparison fail outright (fatal error)? Or
> should it still be seen as defined? I'm mostly just curious ;-)
> 

I'm a little further along in looking at this. It's looking messy.

I think we need to start with the fact #ifdef, #ifndef and #undef have 
ALWAYS been #ifIdDefined, #ifIdNotDefined and #undefineId. Going back to 
the v3.6 documentation we have:

---------------
2.2.2.6.2 The #ifdef and #ifndef Directives

The #ifdef and #ifndef directive are similar to the #if directive 
however they are used to determine if an identifier has been previously 
declared.

IFDEF_DIRECTIVE:
     #ifdef ( IDENTIFIER ) TOKENS... [#else TOKENS...] #end
IFNDEF_DIRECTIVE:
     #ifndef ( IDENTIFIER ) TOKENS... [#else TOKENS...] #end

If the IDENTIFIER exists then the first group of tokens is parsed 
normally and the second set is skipped. If false, the first set is 
skipped and the second set is parsed. ...
----------------

So... The up front, not so good, news is the behavior of at least the 
#ifdef and #ifndef keywords was partly changed back in March of 2015. 
Intentional or accidental? It's not mentioned as an intended change 
anywhere I have seen - and I still don't understand how it happened even 
with some time reviewing the changes when it happened.

Christoph went on to add a bunch of inbuilt keywords to be considered 
'defined' sometime after late November 2018 - which makes me begin to 
think he too might have been considering these *def keywords in the 
c/c++ coding, macro test sense.

The few 'keywords' I've tested these generate a warning in at least some 
versions of POV-Ray. But it's weird, keywords NOT returning immediate 
numbers or strings are also considered 'defined' in these versions 
though they are in fact arbitrary SDL keywords.

Even this worked in the pre-backed off v3.8 release parser:

#ifdef(#declare V=99;#undef V)
...

Though without some other mistake it would usually die with a later 
unmatched something parsing fail. That said it's not hard to get it to 
parse clean - say with an added #if(). I will always die if somebody 
tries use the undef'd V.

So, much more was being supported as testing true in povr/v4.0, but 
still not some things like raw vectors. Though things like x,y,z are OK.

Christoph backed up the v3.8 parser and again lost the inbuilt keywords 
as "defined". I do not know the reasons for the parser backup, but 
perhaps this issue it - or big part of it. I don't know.

I do know, I've got a mess with these in the povr parser given my branch 
point... :-(


When I test v3.7, v3.8b2 and my povr(v4.0?) code I get:

v3.7
----------------------
GOOD_ID  --> This is a valid ID. (ifdef returning true)
GOOD_ID  --> This is a valid ID. (ifndef returning false)
BAD_ID   --> This is NOT a valid ID. (ifdef returning false)
BAD_ID   --> This is NOT a valid ID. (ifndef returning true)
"STRING" --> Other than an ID. (ifdef returning false)
"STRING" --> Other than an ID. (ifndef returning true)
""       --> Other than an ID. (ifdef returning false)
""       --> Other than an ID. (ifndef returning true)
1.23456  --> Other than an ID. (ifdef returning false)
1.23456  --> Other than an ID. (ifndef returning true)
0        --> Other than an ID. (ifdef returning false)
0        --> Other than an ID. (ifndef returning true)
pi       --> Other than an ID. (ifdef returning false)
pi       --> Other than an ID. (ifndef returning true)
          --> Other than an ID. (ifdef returning true)
          --> Other than an ID. (ifndef returning true)

v3.8b2
-----------------------
GOOD_ID  --> This is a valid ID. (ifdef returning true)
GOOD_ID  --> This is a valid ID. (ifndef returning false)
BAD_ID   --> This is NOT a valid ID. (ifdef returning false)
BAD_ID   --> This is NOT a valid ID. (ifndef returning true)
"STRING" --> Other than an ID. (ifdef returning true)        ***
"STRING" --> Other than an ID. (ifndef returning false)      ***
""       --> Other than an ID. (ifdef returning true)        ***
""       --> Other than an ID. (ifndef returning false)      ***
1.23456  --> Other than an ID. (ifdef returning true)        ***
1.23456  --> Other than an ID. (ifndef returning false)      ***
0        --> Other than an ID. (ifdef returning true)        ***
0        --> Other than an ID. (ifndef returning false)      ***
pi       --> Other than an ID. (ifdef returning false)
pi       --> Other than an ID. (ifndef returning true)
          --> Other than an ID. (ifdef returning true)
          --> Other than an ID. (ifndef returning true)

povr & likely v4.0 and other misc releases before parser backup
-------------------------
GOOD_ID  --> This is a valid ID. (ifdef returning true)
GOOD_ID  --> This is a valid ID. (ifndef returning false)
BAD_ID   --> This is NOT a valid ID. (ifdef returning false)
BAD_ID   --> This is NOT a valid ID. (ifndef returning true)
"STRING" --> Other than an ID. (ifdef returning true)        ***
"STRING" --> Other than an ID. (ifndef returning false)      ***
""       --> Other than an ID. (ifdef returning true)        ***
""       --> Other than an ID. (ifndef returning false)      ***
1.23456  --> Other than an ID. (ifdef returning true)        ***
1.23456  --> Other than an ID. (ifndef returning false)      ***
0        --> Other than an ID. (ifdef returning true)        ***
0        --> Other than an ID. (ifndef returning false)      ***
pi       --> Other than an ID. (ifdef returning true)        ###
pi       --> Other than an ID. (ifndef returning false)      ###
          --> Other than an ID. (ifdef returning true)
          --> Other than an ID. (ifndef returning true)

The last case with empty parens is an exposure back to v3.7. In a lot of 
code the effective fall through at the #if____ will cause later parsing 
problems, but the error are of the more unhelpful sort. It would be best
if the empty parens were themselves a parse error. I 'think' it's 
probably also possible to fix the following parsing issues with another, 
cleaning syntax (actual bad-syntax) sort of mistake.

My feeling is the right thing to do would be to take the behavior back 
to what it has always been with the nearer term v3.8 release. If we want 
the most backward compatibility this it. Further, the extra now being 
changed currently in the v3.8 code is not consistent with respect to 
things like pi - which to the parser is an immediate value of pi. And 
datetime would be an example of an immediate string which would test 
true, you'd think, if "string" does.

What to do... I could spend a lot of time trying to figure out the 
history here, but I think the current state not completely tenable since 
2015...

We need functionality which deals only with IDs.

We, perhaps, need some sort of what is in the parenthesis is 'defined' 
functionality too, but the generic sort being allowed or not seems 
questionable to me. Are people already using this functionality?

With povr I might do something drastic like create 'id' versions and and 
'defined' versions - with all new keyword names so users would be forced 
to look at potential problems with interpretation and behavior given the 
old keywords wouldn't work!

Hmm... We do have new to v3.8 the local and global dictionaries. Could I 
just dump the #ifdef and #ifndef keyword for something based on those. I 
can't remember at the moment how they work.

Don't know... Whatever it is in povr, afraid at the moment it'll be a 
lot of work - because I'll need to digest a lot of the parser code.

Guess it's time to do my taxes... :-)

Bill P.


Post a reply to this message

From: Bald Eagle
Subject: Re: #ifdef using a string expression?
Date: 19 Mar 2023 17:55:00
Message: <web.6417846d98df09c91f9dae3025979125@news.povray.org>
William F Pokorny <ano### [at] anonymousorg> wrote:

> The few 'keywords' I've tested these generate a warning in at least some
> versions of POV-Ray. But it's weird, keywords NOT returning immediate
> numbers or strings are also considered 'defined' in these versions
> though they are in fact arbitrary SDL keywords.

I think you're going to run into the same hamstringing that an over-concern
about backwards compatibility inevitably results in.  If any of this stuff is
going to be fixed, there needs to be a clean break, and a sane, logical,
rational, basis for moving forward.

> Even this worked in the pre-backed off v3.8 release parser:
> #ifdef(#declare V=99;#undef V)
> Though without some other mistake it would usually die with a later
> unmatched something parsing fail.

That looks fine - given someone may have some reason to do that.  Some sort of
quick bypass workaround.


> I will always die if somebody tries use the undef'd V.

Yes.  Because V is for Victory, and undefining it results in Failure.  :P

> So, much more was being supported as testing true in povr/v4.0, but
> still not some things like raw vectors. Though things like x,y,z are OK.

.....

> Further, the extra now being
> changed currently in the v3.8 code is not consistent with respect to
> things like pi - which to the parser is an immediate value of pi. And
> datetime would be an example of an immediate string which would test
> true, you'd think, if "string" does.
>
> What to do... I could spend a lot of time trying to figure out the
> history here, but I think the current state not completely tenable since
> 2015...
>
> We need functionality which deals only with IDs.
>
> We, perhaps, need some sort of what is in the parenthesis is 'defined'
> functionality too, but the generic sort being allowed or not seems
> questionable to me. Are people already using this functionality?

I use and abuse whatever I can find as a workaround for lack of functionality.
I absolutely don't mind rewriting code to perform with a new and better version.

Currently trying to implement some geometric testing code, it's becoming
increasingly clear that we have plenty of raytracing capability, and missing
programming code to make coding the scenes easier and more capable.

Example:
I'm testing for an intersection.  What do I do in SDL if there's a) none, or b)
more than 1?   Or if I'm looking at parallel or skew lines.  Or the user or the
circumstances require the endpoints of a line to be the same (a point)?

I'm dreaming up workarounds like mixed arrays with succeed/fail flags followed
by the variable number of results (line/line | line/circle | circle/circle).
For data type cast, I'm thinking I need a 2D mixed array with the [0] holding
the data type as a string, and the actual data in the 1[].

It would be so much easier to code these things (and faster) if we had some
tools to deal with variable results.

null, NaN, variable type detection, error trapping, etc.
It would make testing with #ifdef a little more sane if #ifdef (keyword)
returned a versatile value that I could make use of in a broad number of
circumstances.

First - I think POV-Ray needs to sort out keywords vs values, scalars vs
vectors, vs parse/render/function space variable names.  It's confusing, and is
contributing directly to the mess you're trying to sort out. You can't.  It's
all inextricably mixed.  clipka correctly pointed out that all of this stuff
needs to get disentangled in the parser.

So, I would say that "if" should return a value that denotes keyword,
whereas "pi" should return a value that denotes a reserved value.  "CONST", or
whatever that compiler one is.  "PRAGMA"

It's "nice" that I can swizzle things all over the place between vectors and
colors, etc.  But it makes for lazy / bad programming practices.  Better the
ability to recast a value from a scalar to a vector to a color, etc.

It would probably take me a month, tops, to adapt to the new requirements, and
I'd be able to write better, shorter, more easily understood and maintained
code.  Further, if there were sufficient programmatic capability, "fixes" for
old scenes could be coded, much like TOK and I code custom functions and macros
to handle pow (0, 0), factorial, N choose M, mod () crossing the origin, etc.
Just change the keyword in the old scene to a capitalized version ("We love you,
jr!") and boom - you have a macro that could possibly handle a lot of the
backward compatibility with a simple find/replace on the old scene file.

The first rule of holes is: when you find yourself in one, stop digging.
The second is: climb out.

I'd rather suffer now, and profit later.


Post a reply to this message

From: Kenneth
Subject: Re: #ifdef using a string expression?
Date: 19 Mar 2023 23:45:00
Message: <web.6417d58798df09c99b4924336e066e29@news.povray.org>
William F Pokorny <ano### [at] anonymousorg> wrote:
>

Thanks for doing such a detailed series of tests and an examination of the
various code versions! I can imagine that it was a lot of drudgery.

> I think we need to start with the fact #ifdef, #ifndef and #undef have
> ALWAYS been #ifIdDefined, #ifIdNotDefined and #undefineId. Going back to
> the v3.6 documentation we have:
> [clip]
>
> We need functionality which deals only with IDs.
>
> ...but the generic sort being allowed or not seems
> questionable to me.

I agree; IMO, #ifdef etc. should adhere to the much more strict behavior
described in the docs. Admittedly, I am not as sophisticated a user of these
functions as some others are, but the current behavior seems quite lax and could
lead to unintended scene errors or coding 'mysteries'.

And I would be happier if my silly string-literal example produced a fatal
error! Otherwise, I can't imagine a scenario where a 'naked' string would even
be used there.

I also think that using an *actual* zero or a float (while having some meaning
as boolean values) does not really represent a 'valid ID' as per docs, and so
should fail outright as well. My opinion ;-) HOWEVER... I can see a scenario
where 0 or 1 could be used simply to test whether a scene's specific #ifdef
construct is working properly or not-- in other words, without relying on an
actually-defined identifier for the test. On the other hand...it would be a
simple matter to pre-define a temp dummy identifier for the same use.

> Christoph went on to add a bunch of inbuilt keywords to be considered
> 'defined' sometime after late November 2018 - which makes me begin to
> think he too might have been considering these *def keywords in the
> c/c++ coding, macro test sense.

Actually, it's not clear to me why any keywords at all would or should be valid
'parameters' for an #ifdef comparison-- but I'm rather naive at present about
what might be such a useful coding scenario. For example, my own rather
meaningless(?) test of
               #ifdef(true)
appears to be a flat-out mistaken use of the function, since the comparison will
(or rather, *should*) always invoke the first clause, never the #else. In other
words, this construct should use #if or #while or #switch or etc, not #ifdef.

I am obviously not seeing why a keyword could be meaningfully used there.


----------
In general, I think that most of not all of the non-fatal error messages re:
#ifdef should be changed to fatal-- if only as a guard against using entities
that don't belong there and need changing. Personally, I'm lazy about taking
note of non-fatal messages.


Post a reply to this message

From: jr
Subject: Re: #ifdef using a string expression?
Date: 20 Mar 2023 03:20:00
Message: <web.641808dd98df09c94301edef6cde94f1@news.povray.org>
hi,

"Kenneth" <kdw### [at] gmailcom> wrote:
> William F Pokorny <ano### [at] anonymousorg> wrote:
> ...
> Actually, it's not clear to me why any keywords at all would or should be valid
> 'parameters' for an #ifdef comparison ...

one use I see, though I have never tried/used it, is determining whether a given
keyword (already) exists in the POV-Ray version doing the parsing; if it worked
for, eg, 'tau'.  also, fwiw, agree that parsing (generally) should be "strict".


regards, jr.


Post a reply to this message

From: Alain Martel
Subject: Re: #ifdef using a string expression?
Date: 20 Mar 2023 11:11:17
Message: <64187795$1@news.povray.org>
Le 2023-03-19 à 10:41, Bald Eagle a écrit :
> "Kenneth" <kdw### [at] gmailcom> wrote:
> 
>> Given the current mix of flaws, the use of a string literal still has me
>> scratching my head...
>>          #ifdef("...string...")
>>
>> Alain's and JR's explanation of the expected behavior seems valid; but with a
>> properly-working #ifdef, should the comparison fail outright (fatal error)? Or
>> should it still be seen as defined? I'm mostly just curious ;-)
> 
> One might suggest:
> "Expected variable name, literal value found instead."
> 
> -or- "It is what is is." ;)
> 
> 
> 
> 
> The correct answer for me has always been OPTIONS.
> 
> When everything gets locked into a one-right-answer only format, it usually just
> creates new problems in the process of "solving" the old.
> 
> I was just reading some old threads concerning this type of thing, and the
> degenerate triangle warning vs 0-length fatal error for cylinders was brought
> up.
> 
> For some scenes it could be a critical thing to stop the render.   For others,
> you might want to just ignore them all.  Usually these things are addressed by
> the users with workarounds, but why not have a configuration file that states
> how to handle these cases, an additional argument for the object instantiation
> that provides for individual control, or an error-trapping mechanism (with error
> code) that allows the user to write their own programmatic/logical solution
> based on further testing and flow control, and allows the user to issue better
> warnings that the cryptic ones currently hard-coded in source?
> 
> 
> 

Or even a global_settings entry, such as :
Ignore_degenerate true|false //default to false


Post a reply to this message

From: Kenneth
Subject: Re: #ifdef using a string expression?
Date: 20 Mar 2023 21:20:00
Message: <web.6419062498df09c99b4924336e066e29@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:
>
> "Kenneth" <kdw### [at] gmailcom> wrote:
> >
> > Actually, it's not clear to me why any keywords at all would or should
> > be valid 'parameters' for an #ifdef comparison ...
>
> one use I see, though I have never tried/used it, is determining whether a given
> keyword (already) exists in the POV-Ray version doing the parsing; if it worked
> for, eg, 'tau'.
>

Ah! Yes, I see the usefulness of that. Thanks. That totally escaped me. My
#ifdef(true) example was a bad choice to illustrate the situation.

> > And I would be happier if my silly string-literal example produced a fatal
> > error! Otherwise, I can't imagine a scenario where a 'naked' string would
> > even be used there.


Post a reply to this message

From: Kenneth
Subject: Re: #ifdef using a string expression?
Date: 20 Mar 2023 23:35:00
Message: <web.6419252d98df09c99b4924336e066e29@news.povray.org>
I hit the 'post' button too soon :-/

> And I would be happier if my silly string-literal example produced a fatal
> error! Otherwise, I can't imagine a scenario where a 'naked' string would even
> be used there.
>

Well, on 2nd thought, I do see at least one special-case string use: To try to
easily determine if a particular #include file is actually present in a scene.
Like:
              #ifdef("my sphere file.inc")
or maybe a no-string version:  #ifdef(my sphere file.inc)
                           or  #ifdef(my sphere file)

Nothing like this works in v3.8xx. Of course, #ifdef may not be the correct
thing to use, but it's the first idea that comes to mind. (I have a vague
memory-- possibly mistaken-- that I did use the string- construct version in the
*distant* past, and that it worked. Or maybe not.) But with the current behavior
of #ifdef("...string..."), it's of no use. And   (my sphere file.inc)   fails
outright because of the 'dot'; likewise   (my sphere file)  because of the
spaces.

There IS an obscure built-in identifier (or variable?) called
View_Include_Stack, that can be used to determine if any of POV-ray's *own*
specific include files are present-- ALL that are being used-- by putting the
following at the top of a scene, running it, then looking afterward in
'Messages' (in Windows GUI versions, that is):
                     #declare View_POV_Include_Stack = true;

I can't find it in the documentation; but take a look here...
https://news.povray.org/povray.general/thread/%3C5c0827cd%241%40news.povray.org%3E/

Unfortunately, it will not list any user-made #includes-- even if they are
placed in POV-ray's 'includes' folder; I just tested it. That seems strange.

(The link above actually discusses the topic of how to determine the presence of
such user-made files, but the various methods seem to require that code snippets
be added to each and every file first. A simpler #ifdef scheme would be much
easier!)


Post a reply to this message

From: William F Pokorny
Subject: Re: #ifdef using a string expression?
Date: 21 Mar 2023 03:26:38
Message: <64195c2e$1@news.povray.org>
On 3/20/23 23:31, Kenneth wrote:
> Well, on 2nd thought, I do see at least one special-case string use: To try to
> easily determine if a particular #include file is actually present in a scene.

I'm having a hard time seeing a good reason for the capability. If you 
are trying to do something like swap in simple stand in for a complex 
model while developing a scene, it seems like you should just set that 
up on a declared true false variable ahead of time.

Maybe you'd want to automatically use a simple stand end until the 
include of the complex model is created. Well then you could use 
file_exists() and the complex model will be included as soon as it exist 
somewhere POV-Ray can find it.

A failing include stops parsing.

Folks often include far more than they need (stnd.inc ?) for any given 
scene. While that slows down parsing, it usually isn't a fatal mistake.

Unfortunate undefs or re-declares to the same IDs do happen, and that is 
the one place where a user might want to throw an error if, say, he 
knows POV-Ray's color.inc has the potential to undo his flavor or Red. 
But, then maybe, MyBetterThanPOVRayRed is a better name... :-)

Not arguing you couldn't use the functionality, it's just hard for me to 
see the return on investment.

Aside: Even checking the name there is a search order for the file too 
and, if there are multiple files called color.inc available, the next 
feature request will be something about knowing which actual color.inc 
POV-Ray included.

---

I'm thinking, jr, about a keyword_exists() kind of feature.

---

Aside: I'm digging around more on the - since 2015 - ifdef(), ifndef() 
v3.71/v3.8/v4.0 behavior; I noticed when keywords are passed, Christoph 
made updates to some releases to kick out a warning:

Parse Warning:
Trying to test whether a reserved keyword is defined.
Test result may not be what you expect.

(or a similar message depending on releases)

I take it as evidence he was playing with looking at more than IDs - or 
perhaps he realized there was an unintended an unintended behavior he 
needed to back out (a part of it he did for v3.8). For povr I'll likely 
leave the message in place on restoring v3.7 and prior behavior; Users 
can get different results depending on what release code they run on 
testing keywords.

Yep, I need to look at how he made the inbuilt keyword determination for 
the message - there are hidden reserved words too which are not visible 
SDL 'keywords' / reserved words. Msg method might offer a way to an 
iskeyword().

Bill P.


Post a reply to this message

From: Kenneth
Subject: Re: #ifdef using a string expression?
Date: 21 Mar 2023 07:45:00
Message: <web.6419986c98df09c99b4924336e066e29@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:
>
> There IS an obscure built-in identifier (or variable?) called
> View_Include_Stack...

Well... In the light of a new day, I remembered that I had seen that
*somewhere*; it's not an "obscure built-in identifier" :-[  It's just 'a name'
or variable-- part of an #ifdef block at the top of every 'official' POV-ray
include file, with a simple #debug statement:

             #ifdef(View_POV_Include_Stack)
             #debug "including arrays.inc\n"
             #end

It's just a useful/descriptive phrase that someone came up with in the past.
Which explains why adding    #declare View_POV_Include_Stack = true;   at the
top of your main scene file results in a list of those #included files in
'messages'.  Duh. No special magic.

>
> I can't find it in the documentation...
>
...because it's, uh, not part of POV-ray.
>
> Unfortunately, it will not list any user-made #includes-- even if they are
> placed in POV-ray's 'includes' folder; I just tested it. That seems strange.

That's because my personal #include files don't have the added #ifdef block.
Until now, I never gave much thought as to why I should add that. NOW I see why.
It's a good way to see which files might be buried in a large scene with lots of
nested #includes.

I haven't yet tested it to see if it will flag *multiple* instances of the same
#include. That would be useful too.


Post a reply to this message

From: William F Pokorny
Subject: Re: #ifdef using a string expression?
Date: 22 Mar 2023 07:20:27
Message: <641ae47b$1@news.povray.org>
On 3/21/23 07:43, Kenneth wrote:
> Well... In the light of a new day, I remembered that I had seen that
> *somewhere*; it's not an "obscure built-in identifier" πŸ˜…  It's just 'a name'
> or variable-- part of an #ifdef block at the top of every 'official' POV-ray
> include file, with a simple #debug statement:
> 
>               #ifdef(View_POV_Include_Stack)
>               #debug "including arrays.inc\n"
>               #end
> 
> It's just a useful/descriptive phrase that someone came up with in the past.
> Which explains why adding    #declare View_POV_Include_Stack = true;   at the
> top of your main scene file results in a list of those #included files in
> 'messages'.  Duh. No special magic.

With my povr branch I have for a while been set up with two basic 
targeted compiles.

One is a debug option with a lot of extra checking and reporting 
enabled. The other is the day to day rendering version to be used when 
things are going well.

The idea is to use the faster one as a rule.

However, on seeing flaky behavior, or when just wanting to do more 
robust checking of your scene to find what evil is lurking - run the 
debug compile version.

On reading your post I had the thought, why not add some detailed 
include information to the targeted debug compile version of povr. I did 
- and the output currently looks like:

==== [Parsing...] ==============================================
Debug: #include "functions.inc"
Debug: #include "/run/shm/tmpDir/povrayB/include/transforms.inc"
Debug: #include "/run/shm/tmpDir/povrayB/include/math.inc"
Debug: #include "functions.inc"
Debug: #include "/run/shm/tmpDir/povrayB/include/setidtypes.inc"
Debug: #include "/run/shm/tmpDir/povrayB/include/vectors.inc"
Debug: #include "/run/shm/tmpDir/povrayB/include/vectors.inc"
Debug: #include "/run/shm/tmpDir/povrayB/include/math.inc"
Debug: #include "/tmp/otherInc/whackJob.inc"

This information which I'll find useful on occasion too! Oh, the scene 
has only these four includes:

#include "functions.inc"
#include "transforms.inc"
#include "math.inc"
#include "whackJob.inc"

So, the larger reported set is due some of those includes having 
includes too. With well formed include files, only the first in the 
debug output is really used.

On using: #declare View_POV_Include_Stack = 1; we see:

including function.inc
including transforms.inc
including math.inc
including setidtypes.inc
including vectors.inc

We don't see whackJob.inc just above because the guy who wrote it did 
not add the debug code that is in all core shipped include files.

Aside: There are exposures with the View_POV_Include_Stack method in 
that the name reported is whatever is in the debug statement and not 
really the name of the file included. They should align, but...

---

With regards to the #ifdef(), #ifndef(), the povr fork has been reverted 
to v3.7,v3.6 behavior in looking only for declared IDs. With the one 
exception that empty parenthesis now returns false or true, 
respectively, without introducing odd, hard to understand parsing fails 
as a rule.

Bill P.


Post a reply to this message

From: Kenneth
Subject: Re: #ifdef using a string expression?
Date: 23 Mar 2023 15:05:00
Message: <web.641ca22b98df09c99b4924336e066e29@news.povray.org>
William F Pokorny <ano### [at] anonymousorg> wrote:
>
> Aside: There are exposures with the View_POV_Include_Stack method in
> that the name reported is whatever is in the debug statement and not
> really the name of the file included. They should align, but...
>

Yes! I was a 'victim' of that user error myself, while I was testing things :-[
A sloppy cut-and-paste job. I spent half an hour (!) tracking it down, ha.

This old method is certainly not an ideal way to report the presence of a user's
personal #includes. The special code block is 'one more thing' that has to be
added to a file. I probably have several hundred includes of different kinds
that I have written over the years, many written hastily (or even auto-generated
by POV-ray like mesh_2 files.)


Post a reply to this message

From: William F Pokorny
Subject: Re: #ifdef using a string expression?
Date: 24 Mar 2023 09:53:27
Message: <641dab57$1@news.povray.org>
On 3/23/23 15:02, Kenneth wrote:
> This old method is certainly not an ideal way to report the presence of a user's
> personal #includes.

Found the new debug compile reporting all the include read attempts has 
an issue too.

Specifically where people use that Parse_String() macro hack. It works 
by creating and including a small include file of the same name, but 
with different contents.

In trying again to debug that flaky csv read file problem from early 
2022 of jr's, I was getting thousands of debug include messages per 
frame of a long animation! So, I commented out that nice debug code I 
just added.

I'm unsure what to do for anything shipped.We'd need a custom 
configuration option or a new run time flag/option - neither of which is 
attractive.

It's hard to get simple, clean, code wins. :-)

Bill P.


Post a reply to this message

From: jr
Subject: Re: #ifdef using a string expression?
Date: 24 Mar 2023 11:40:00
Message: <web.641dc38498df09c94301edef6cde94f1@news.povray.org>
hi,

William F Pokorny <ano### [at] anonymousorg> wrote:
> ...
> I was getting thousands of debug include messages ...
> I'm unsure what to do for anything shipped.

a '#pragma [no-]feature-warning;' would be real nice, to get rid (selectively)
of spline + rtr "experimental feature" warnings, for instance :-)


regards, jr.


Post a reply to this message

From: William F Pokorny
Subject: Re: #ifdef using a string expression?
Date: 24 Mar 2023 11:51:02
Message: <641dc6e6$1@news.povray.org>
On 3/24/23 11:36, jr wrote:
> a '#pragma [no-]feature-warning;' would be real nice, to get rid (selectively)
> of spline + rtr "experimental feature" warnings, for instance πŸ˜„

Hmm. Yeah, maybe some more general mechanism to turn off messages would 
be helpful(a,b). Features like this will slow down the parser some though.

Bill P.

(a) - The was some support for warning levels for a time, but it's 
eroded on the implementation side over time - unsure if it still works 
at all in fact. Plus, I cannot remember how the level was specified at 
the moment.

(b) - Unrelated to parsing, but for the isosurface only I added a report 
<true/fase> option in povr for gradient messages. The 'report' keyword 
has always intended to be a more general thing which could be used with 
all the shape primitives. Something where, by shape, you can turn 
reporting on and off. I never seem to get back to working on the concept 
though...


Post a reply to this message

From: Kenneth
Subject: Re: #ifdef using a string expression?
Date: 25 Mar 2023 04:30:00
Message: <web.641eb06698df09c99b4924336e066e29@news.povray.org>
William F Pokorny <ano### [at] anonymousorg> wrote:
> On 3/23/23 15:02, Kenneth wrote:
> >
> > This old method [of 'View_POV-Include_Stack'] is certainly not an ideal
> > way to report the presence of a user's personal #includes.
>
> I'm unsure what to do for anything shipped. We'd need a custom
> configuration option or a new run time flag/option - neither of which is
> attractive.
>
> It's hard to get simple, clean, code wins. :-)
>

I was thinking the same thing: something built-in. HOW to do it-- and how
difficult it would be to code without introducing other problems-- are the
bigger questions, of course ;-)

I'm rather surprised that, in all the years of POV-ray's code development, some
kind of internal mechanism was not introduced to do this... because knowing
automatically which #includes are actually being used in a scene would be a
useful bit of info, IMO.

In the 'official' Windows versions, the GUI uses something called CODEMAX, as
far as I understand. Perhaps the lack of such an #includes feature is a
limitation of the POV-ray/CODEMAX interaction? I do remember Clipka and other
developers mentioning 'difficulties' or restrictions between the two.


Post a reply to this message

From: Bald Eagle
Subject: Re: #ifdef using a string expression?
Date: 25 Mar 2023 07:40:00
Message: <web.641edd2a98df09c91f9dae3025979125@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:

> I was thinking the same thing: something built-in. HOW to do it-- and how
> difficult it would be to code without introducing other problems-- are the
> bigger questions, of course ;-)

Seems to me (a non-source-code-programmer) that it would work as part of the
#include directive itself, and we already have internal things like recursion
stacks, etc.  So it wouldn't really be a problem to prevent multiple parsing of
includes, etc.
As for parse time, how much extra could there possibly be to check the include
stack to see if the file has been included yet, or if the "view include stack"
flag is set or not?

But perhaps for some reason it's non-trivial.

- BW


Post a reply to this message

From: William F Pokorny
Subject: Re: #ifdef using a string expression?
Date: 26 Mar 2023 02:59:26
Message: <641fed4e$1@news.povray.org>
On 3/25/23 07:38, Bald Eagle wrote:
> As for parse time, how much extra could there possibly be to check the include
> stack to see if the file has been included yet, or if the "view include stack"
> flag is set or not?

Mostly very little as you suggest.

Excepting where someone is using the Parse_String hack or similar and so 
doing potentially gazillions of small includes - as is happening in the 
animation code of jr's. The clean fix for that problem is to change that 
hack into some immediate, interpret this 'string' feature - but that's 
not all that easy to do.

In any case, I was thinking more of jr's general #pragma capability for 
turning off say 13 warnings, but not any of the other remaining 3,852 (I 
made that number up).

We introduced the possible errors category too as something I believe 
new to v3.7/v3.8/v4.0, but I didn't go check the v3.6 source.

Thinking aloud...

In compilers most all warnings are introduced with a general, less 
general and selective control capability(a), but also various categories 
of warnings. These are almost all on command line flags and often inline 
with code too. In code these optionally to some local region (like a 
file or particular functions) in the form of #pragma settings. That 
said, such message controls are not all that standardized between 
compilers. What you do for one compiler might or might not work for 
others. And sometimes there are conflicts between compilers.

POV-Ray is a little different from compilers in that we have a parse 
phase, which is compiler like is some respects, and then we have a 
render phase for both stills and animations. Those two modes differ in 
behavior and cost.

Aside: We have too a nascent RTR capability too not sharing much with 
the control structure of regular animations.

The issues start with the code base not having a generic set up for 
anything like an in code #pragma capability - which probably would apply 
to SDL only I'd say.

We have too what looks like common functionality in things like pow() 
that have multiple forms internally. One for the SDL and another for 
functions running on the vm at parse time or render time.

We have warnings and errors around both command line options and ini 
settings too. These perhaps more an issue for animations where you might 
get some warning for each frame.

The error messages don't all go through the same message systems or 
message handlers today. In povr, I use the fancier ones when they are 
there and ready to use, but when they are not, I don't!

I've made use of writing to stderr, for example, when it's the expedient 
thing to do to get messages about behavior where we are today just 
letting things go. Often things which were historically reported in 
earlier single thread versions of POV-Ray. Yes, this means sometimes 
each thread kicks out exception messages, but I feel getting the 
information is more important than not.

That's sort of the really rough lay of the land for info / warning / 
possible error / error / messages. The thinking aloud, I expect, more 
helpful to me than anyone else. :-)

All that said, adding a few select controls, #pragmas, not all that hard 
to do. Maybe we aim to control the most annoying (or most useful) 
messages first.

Where these might bleed over to render time functionality there is a 
significant cost to turning on or off checks when that 'control test' 
gets done millions (or billions) of times while rendering. Such testing 
costs less for animations where you might have only a thousand frames. 
For stills such control tests might cost little or be significant if 
happening inside a loop placing thousands of objects.

Yes, issuing and tracking information for the messages costs too. 
Sometimes we'll win when the messages are off - even if running the 
control test a great many times.

Sometimes messages are situation-ally useless as happens when users 
create isosurfaces with functions having a high gradients - well away 
from the all of the actual roots. In such cases the gradient warnings 
have no 'useful' meaning and in povr 'report false' turns them off by 
isosurface.

There are situations where better more controllable warnings absolutely 
helps limit warnings to those probably useful.

Bill P.

(a) - Aside. When I re-worked povr's gnu, autotools based build, I 
turned off all the compiler warnings by default. To me,  it didn't make 
sense for users grabbing the code to do a quick ./configure, make -j4, 
make check, make install; to see hundreds of warnings they aren't going 
to try and fix anyway.


Post a reply to this message

From: Bald Eagle
Subject: Re: #ifdef using a string expression?
Date: 26 Mar 2023 07:55:00
Message: <web.6420316898df09c91f9dae3025979125@news.povray.org>
My my, you _have_ been busy   :O


Is there a way to identify and collect all of the places in source where errors
get raised, and group them by parse / render/ etc?

That might help folks get a better idea about how much there is an how often
some warnings might need to test conditions and fork flow control.

While working on the lemon, I also stumbled upon a dev manual in the 3.8 github
stuff - haven't had a chance to dig through it - might any of that already be in
there?

- BW


Post a reply to this message

From: William F Pokorny
Subject: Re: #ifdef using a string expression?
Date: 26 Mar 2023 09:06:21
Message: <6420434d$1@news.povray.org>
On 3/26/23 07:50, Bald Eagle wrote:
> Is there a way to identify and collect all of the places in source where errors
> get raised, and group them by parse / render/ etc?
> 

:-) Hmm. Asking questions to which to which the only strict answer is 
yes.

If you mean quickly, you can grep strings like Warning, PossibleError, 
Error and see quite a bit of text fly by. When and whether you actually 
get any particular ones depends on more. Some too get formed indirectly 
where a function like Not_WithPattern() might be what is actually 
getting called and it will assemble some final Error or Warning.

The parsing related stuff these days is mostly in the source/parser 
directory. Just counting lines with those strings in povr, Warning 171,
PossibleError 32, Error 609.

> 
> While working on the lemon, I also stumbled upon a dev manual in the 3.8 github
> stuff - haven't had a chance to dig through it - might any of that already be in
> there?

Assume you are talking about the contents of source-doc directory.

Many years ago I did read through those files. I don't recall much of it 
truth be told and a lot of it was 15 years old already when I read it. I 
see a povms.md file. It would have stuff on the threaded messaging 
system - one of several ways messages get generated - so yep some in 
there. :-)

Bill P.


Post a reply to this message

From: Kenneth
Subject: Re: #ifdef using a string expression?
Date: 11 Apr 2023 08:25:00
Message: <web.64354efe98df09c99b4924336e066e29@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:
> (v3.8.0 beta 1 in Windows 10)
>
> I was playing around with #ifdef recently; just experimenting.
>
Here's another example of an #ifdef feature that would be useful, IMO. I
recently had a need for it:
     #ifdef(AA & BB)

Apparently, it doe not (yet) work with 'tuples' like the newer v3.8 #declare
does, for example. Nor with boolean operators, so it seems.

I tried several workarounds for this, in various syntax forms. My first attempt
was with nested #ifdef's, possibly using an #elseif somewhere-- but I am not
very familiar with the #elseif construct and could not come up with a code
block that seemed 'reliable' or logically consistent:

#declare AA=3;
#declare BB=7;

#ifdef(AA)
     #ifdef(BB)
     ... do this...
    (or  #elseif   ...do this... ?)
#else (?)
... do that...
#end

My 2nd attempt was with an enclosing #if, again in various syntax forms-- but
this causes fatal errors, and I'm not sure that I understand why:

#if(#ifdef(AA) & #ifdef(BB)) // this line does not work, even though an #if can
                             // itself use boolean operators
...do this...
#else
...do that...
#end

For the first line, a simpler  #if(#ifdef(AA)) does not work either, nor does
#if(#ifdef(AA)=true))

Any suggestions or comments? It seems to me that at least one of these schemes
*should* work, unless I'm making a basic error or wrong assumption somewhere.

The current v3.8 operation of #ifdef is...ill-defined... so maybe that's part of
the problem(?)


Post a reply to this message

From: jr
Subject: Re: #ifdef using a string expression?
Date: 11 Apr 2023 08:50:00
Message: <web.643556bf98df09c94301edef6cde94f1@news.povray.org>
hi,

"Kenneth" <kdw### [at] gmailcom> wrote:
> "Kenneth" <kdw### [at] gmailcom> wrote:
> > (v3.8.0 beta 1 in Windows 10)
> >
> > I was playing around with #ifdef recently; just experimenting.
> > ...
> For the first line, a simpler  #if(#ifdef(AA)) does not work either, nor does
> #if(#ifdef(AA)=true))
>
> Any suggestions or comments?

suggestion.  write '#if(defined(AA) & defined(BB))'  (ie both exist)


regards, jr.


Post a reply to this message

From: Kenneth
Subject: Re: #ifdef using a string expression?
Date: 11 Apr 2023 10:50:00
Message: <web.643572cd98df09c99b4924336e066e29@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:
>
> "Kenneth" <kdw### [at] gmailcom> wrote:
>
> >  ...
> > For the first line, a simpler  #if(#ifdef(AA)) does not work either, nor does
> > #if(#ifdef(AA)=true))
> >
> > Any suggestions or comments?
>
> suggestion.  write '#if(defined(AA) & defined(BB))'  (ie both exist)
>

Yes, that's a great workaround! Thanks. I had forgotten about the  'defined'
function, as I don't use it very often.


Post a reply to this message

From: Bald Eagle
Subject: Re: #ifdef using a string expression?
Date: 11 Apr 2023 13:30:00
Message: <web.6435984498df09c91f9dae3025979125@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:
> I recently had a need for it:
>      #ifdef(AA & BB)
>
> Apparently, it doe not (yet) work with 'tuples' like the newer v3.8 #declare
> does, for example. Nor with boolean operators, so it seems.

> Any suggestions or comments? It seems to me that at least one of these schemes
> *should* work, unless I'm making a basic error or wrong assumption somewhere.


Depending on how many variables you need to test, you lump them all together
into an array and cycle through them, using the product of the result as a sort
of Boolean AND result.

Not sure I knew about "defined" - that's a handy keyword.

#declare AA = 1;
#declare BB = 3;

#declare Variables = array {AA, BB}


#macro And (_Array)
 #declare Elements = dimension_size (_Array, 1)-1;
 #declare AndResult = 1;
 #for (Index, 0, Elements)
  #declare AndResult = AndResult * defined (_Array[Index]);
 #end

 AndResult
#end


#if (And (Variables))
 #debug "All variables are defined. \n"
#end

#error "No objects in scene"d


Post a reply to this message

From: Kenneth
Subject: Re: #ifdef using a string expression?
Date: 13 Apr 2023 13:25:00
Message: <web.64383a5198df09c99b4924336e066e29@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Kenneth" <kdw### [at] gmailcom> wrote:
>
> >   #ifdef(AA & BB)
> > Any suggestions or comments?
>
> Depending on how many variables you need to test, you lump them all together
> into an array and cycle through them, using the product of the result
> as a sort of Boolean AND result.
>
>
> #declare AA = 1;
> #declare BB = 3;
>
> #declare Variables = array {AA, BB}
>
> #macro And (_Array)
>  #declare Elements = dimension_size (_Array, 1)-1;
>  #declare AndResult = 1;
>  #for (Index, 0, Elements)
>   #declare AndResult = AndResult * defined (_Array[Index]);
>  #end
>  AndResult
> #end
>
>
> #if (And (Variables))
>  #debug "All variables are defined. \n"
> #end
>

I had to think about this one (and had to take a temporary break because of all
of the new Spring pollen in the air, here in the South. Sneezing uncontrollably!
Me no likey!)

This is an interesting way of attacking the problem, and works fine as-is. But
if I add an UN-declared variable to the array (i.e., wondering if I had
previously declared it or not), this line fails:
           #declare Variables = array {AA, BB, CC}

"Cannot pass uninitialized identifier to non-optional array initializer."
(What a mouthful!)

But I'm probably going outside the scope of my simpler  #ifdef(AA & BB)
question. JR's #if/#else code allows a more graceful exit though: I could add a
#debug like, "One or more of your variables is undefined."


Post a reply to this message

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