| The reason is this:
1) if ... then is evaluated at i-time when gival == 0
Since the condition is true, both print statements will be executed. At this stage (initi-pass) only print is executed
2) instr 2 changes the value of gival to 2 at its init-pass
3) the printk statement now runs at performance time and correctly reads the global var value (now 2).
NB: if you start instr 1 1-kcycle after instr 2, nothing will print.
Victor
On 17 Feb 2012, at 20:54, Art Hunkins wrote:
> I don't understand what is happening in the simple csd below:
>
> During the init pass, gival is initialized to 0, but instr 2 changes it to 2. Meanwhile, instr 1 correctly evaluates it to 0, falling into the if/then construction (print gival), the condition being true.
>
> During the k passes, instr 1, consistently prints (printk) gival as = 2, as you'd expect - since instr 2 changed its value.
>
> However, *it should never have fallen into the if/then construction*; as the condition is now false (gival == 2).
>
> If the if/then construction is changed to if/goto, the same evaluation error occurs.
>
> This, BTW, is all with the old parser, Windows XP, Csound 5.06. (And of course if instruments 1 and 2 are interchanged, all works as expected.)
>
> What's going on?
>
> Art Hunkins
>
>
>
>
> -odac
>
>
> sr = 44100
> kr = 44100
> nchnls = 1
> gival init 0
>
> instr 1
>
> if gival != 2 then
> print gival
> printk .1, gival
> endif
> endin
>
> instr 2
> gival = 2
> endin
>
>
>
>
> i1 0 1
> i2 0 1
>
> e
>
>
>
>
> Send bugs reports to the Sourceforge bug tracker
> https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>
Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
tel.: +353 1 708 3545
Victor dot Lazzarini AT nuim dot ie
|