 |
 |
|
 |
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
The following line results in an negative subscript error when Z = 0:
#if (Z > 0 & VoxelGrid[X][Y][Z-1] > 0)
I expected the evaluation to terminate, with false, at Z > 0.
Won't say it is a bug, it is just unexpected.
ingo
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"ingo" <nomail@nomail> wrote:
> The following line results in an negative subscript error when Z = 0:
>
> #if (Z > 0 & VoxelGrid[X][Y][Z-1] > 0)
>
> I expected the evaluation to terminate, with false, at Z > 0.
>
> Won't say it is a bug, it is just unexpected.
>
> ingo
I ran into this before. The way I got around it is...
#if(Z>0) #if(array[X][Y][Z-1]>0) do_something.. #end #end
I think it is the negative element of the array is accessed during evaluation
that causes the error.
#ifndef with an array with a negative element or a positive element out of range
will cause an error too. Even throuh clearly element [-1] doesn't exist.
Have Fun!
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"ingo" <nomail@nomail> wrote:
> The following line results in an negative subscript error when Z = 0:
>
> #if (Z > 0 & VoxelGrid[X][Y][Z-1] > 0)
>
> I expected the evaluation to terminate, with false, at Z > 0.
>
> Won't say it is a bug, it is just unexpected.
Hi Ingo
There's some relevant information here:
https://en.wikipedia.org/wiki/Short-circuit_evaluation
In order to program in a more robust and portable way, one should avoid such
constructs that may differ between languages.
I suggest that you split this up into nested #if statements.
--
Tor Olav
http://subcube.com
https://github.com/t-o-k
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmail com> wrote:
>
> https://en.wikipedia.org/wiki/Short-circuit_evaluation
Ah, that clarifies.
It will needs some rethinking, nested #if it will be,
thanks,
ingo
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 08/03/2025 07:28, ingo wrote:
> "Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmail com> wrote:
>>
>> https://en.wikipedia.org/wiki/Short-circuit_evaluation
>
> Ah, that clarifies.
Above all, it shows that it's VERY language-dependent.
> It will needs some rethinking, nested #if it will be,
So, splitting conditions seems to be the only solution with POV.
--
kurtz le pirate
compagnie de la banquise
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
kurtz le pirate <kur### [at] free fr> wrote:
> So, splitting conditions seems to be the only solution with POV.
But not always straight forward,
#if (Z > 0 & VoxelGrid[X][Y][Z-1] > 0)
.....
#else
.....
#end
after splitting #else may not be reached, where it is in the original (VoxelGrid
= 0).
#if (Z > 0)
#if (VoxelGrid[X][Y][Z-1] > 0)
....
#end
#else
....
#end
it needs some thought and the code is way more complex than this. (#switch #case
can be an alternative after turning the conditions into "states")
ingo
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"ingo" <nomail@nomail> wrote:
> But not always straight forward,
> it needs some thought and the code is way more complex than this. (#switch #case
> can be an alternative after turning the conditions into "states")
Maybe fall back onto using some small helper macros just to keep the statements
short and the logic straight.
Or, potentially what you could do is multiply the pseudo-Boolean values instead
of using the "&" operator.
0*0 = 0
0*1=1
1*0=0
- BW
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"Bald Eagle" <cre### [at] netscape net> wrote:
> Maybe fall back onto using some small helper macros [...] Or, potentially what
> you could do is multiply the pseudo-Boolean values [...]
We share a line of thought,
ingo
Post a reply to this message
|
 |
|  |
|  |
|
 |
From: kurtz le pirate
Subject: Re: unexpected evaluation of #if(...)?
Date: 8 Mar 2025 11:47:04
Message: <67cc7488@news.povray.org>
|
|
 |
|  |
|  |
|
 |
On 08/03/2025 12:34, ingo wrote:
> kurtz le pirate <kur### [at] free fr> wrote:
>
>> So, splitting conditions seems to be the only solution with POV.
>
> But not always straight forward,
>
> #if (Z > 0 & VoxelGrid[X][Y][Z-1] > 0)
> .....
> #else
> .....
> #end
>
> after splitting #else may not be reached, where it is in the original (VoxelGrid
> = 0).
>
> #if (Z > 0)
> #if (VoxelGrid[X][Y][Z-1] > 0)
> ....
> #end
> #else
> ....
> #end
>
> it needs some thought and the code is way more complex than this. (#switch #case
> can be an alternative after turning the conditions into "states")
Of corse.
It also depends on what you want to do in the "else" case.
You can also do something like this :
#if ( VoxelGrid[X][Y][(Z>0?Z-1:OTHER)] > 0 )
More tricky
--
kurtz le pirate
compagnie de la banquise
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |