POV-Ray : Newsgroups : povray.general : Why does POV always evaluate both expressions with a '&'? : Re: Why does POV always evaluate both expressions with a '&'? Server Time
7 Aug 2024 11:25:56 EDT (-0400)
  Re: Why does POV always evaluate both expressions with a '&'?  
From: Micha Riser
Date: 27 Sep 2001 12:20:03
Message: <4ijvo9.6d4.ln@micha.riser>
Warp wrote:

> Thorsten Froehlich <tho### [at] trfde> wrote:
> :> #while((i<n)&(a[i]=0))
> :>         #declare i=i+1
> :> #end
> 
> : The above code is illegal in C and C++
> 
>   How so? I don't see anything wrong there (of course if we imagine that
>   we
> convert it to equivalent C code).

Doing that resulted in 

int a[1000];
int main() {

        int i;
        for(i=0;i<1000;i++) {a[i]=0;}
        i=0;    
        while( (i<1000)&&(a[i]==0) )
                {
                printf("%d\n",i);
                i++;
                }

}

works fine with gcc.

> 
>   The C standard *guarantees* that the expression at the right of && is
>   not
> evaluated if the expression at the left is false. (The & operator in
> POV-Ray is equivalent to the && operator in C, and it should not be
> confused with the & operator in C, which does a completely different
> thing.)
>   The example doesn't either modify the same value in the same sentence or
> anything similar. It looks completely ok to me.
> 

Thanks Warp, Thorsten's posting made me unsure about C.


Post a reply to this message

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