Csound Csound-dev Csound-tekno Search About

if-then-else bug in csound5.00

Date2006-02-05 19:12
FromKlaus Schröder
Subjectif-then-else bug in csound5.00
Attachmentsif_else_test.csd  
The if .. then .. else .. endif  code does not work as expected. In 
Csound5.0 an else block following immediately after the if block is executed 
even if the if-condition is true. The if .. then .. elseif .. endif code 
seems to work correctly. This behavior is demonstrated  by the attached 
csd-file:

"Csound version 5.00.0 (double samples) Jan 29 2006" produces the following 
output:

SECTION 1:
new alloc for instr 1:
if (p4=0)
else (p4=0)                          <= this demonstrates the bug
new alloc for instr 1:
else (p4=1)
new alloc for instr 2:
if (p4=0)
new alloc for instr 2:
elseif (p4=1)

The same csd-file with  "Csound Version 4.23f07 (Sep  2 2003)" produces a 
result which is even worse:

SECTION 1:
new alloc for instr 1:
if (p4=0)
new alloc for instr 1:
if (p4=1)
new alloc for instr 2:
if (p4=0)
elseif (p4=0)
new alloc for instr 2:
if (p4=1)
elseif (p4=1)

Regards
Klaus

Date2006-02-05 19:33
FromIstvan Varga
SubjectRe: if-then-else bug in csound5.00
AttachmentsNone  

Date2006-02-06 08:39
From"Matt J. Ingalls"
SubjectRe: if-then-else bug in csound5.00
it looks like there might be  a bug in csound 5.  the csound4 output looks 
right.  if i remember right, p-variables are treated as k-rate variables in 
conditionals. for all k-rate conditionals, every block needs to be 
initialzed at i-time, regardless of the conditional being true or not at 
i-time..

On Sun, 5 Feb 2006, Klaus Schröder wrote:

> The if .. then .. else .. endif  code does not work as expected. In Csound5.0 
> an else block following immediately after the if block is executed even if 
> the if-condition is true. The if .. then .. elseif .. endif code seems to 
> work correctly. This behavior is demonstrated  by the attached csd-file:
>
> "Csound version 5.00.0 (double samples) Jan 29 2006" produces the following 
> output:
>
> SECTION 1:
> new alloc for instr 1:
> if (p4=0)
> else (p4=0)                          <= this demonstrates the bug
> new alloc for instr 1:
> else (p4=1)
> new alloc for instr 2:
> if (p4=0)
> new alloc for instr 2:
> elseif (p4=1)
>
> The same csd-file with  "Csound Version 4.23f07 (Sep  2 2003)" produces a 
> result which is even worse:
>
> SECTION 1:
> new alloc for instr 1:
> if (p4=0)
> new alloc for instr 1:
> if (p4=1)
> new alloc for instr 2:
> if (p4=0)
> elseif (p4=0)
> new alloc for instr 2:
> if (p4=1)
> elseif (p4=1)
>
> Regards
> Klaus
>

Date2006-02-06 10:32
FromIstvan Varga
SubjectRe: if-then-else bug in csound5.00
AttachmentsNone  

Date2006-02-06 12:25
FromIstvan Varga
SubjectRe: if-then-else bug in csound5.00
AttachmentsNone  

Date2006-02-06 16:41
FromIstvan Varga
SubjectRe: if-then-else bug in csound5.00
AttachmentsNone  

Date2006-02-06 18:14
From"Matt J. Ingalls"
SubjectRe: if-then-else bug in csound5.00
>> if i remember right, p-variables are treated as k-rate variables in
>> conditionals.
>
> No, they are i-rate conditionals. If you compile with -v, you should notice

well there was something weird with pfields in conditionals at some point 
there was some discussion about this on the list between steven yi and me 
recently -- maybe its changed since..

Date2006-02-06 18:29
From"Matt J. Ingalls"
SubjectRe: if-then-else bug in csound5.00
> It replaces the cngoto with a cogoto, and kgoto with a goto. However,
> for some reason cogoto always jumps at performance time, so it will
> then always take the 'else' branch and never the 'if'.

i think ithen was designed -- as an inverse-igoto..
maybe it should skip to endif always at p-time?