Hi, there is a bug in the expression evaluation when multiple calls to the same function are made: the return value of the first call(s) are overwritten before being used.
Example program:
Start:
b1=fun1(1)+fun1(2)
goto Start
I ran into this when doing the SSP slave library. I can't speak to a fix, but the workaround per Hugh is using a script inside your function. So I believe your FUN1 would equal my RxBuffersize.
#script ;GCBasic treats AnyArray(1) as variable
RxBufferSize = BufferLen
if BufferLen = 1 then RxBufferSize = 2
#endscript
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, there is a bug in the expression evaluation when multiple calls to the same function are made: the return value of the first call(s) are overwritten before being used.
Example program:
Start:
b1=fun1(1)+fun1(2)
goto Start
function fun1(a1)
fun1=a1+1
end function
Generated assembly:
START
0004 3001 00038 movlw 1
0005 00A0 00039 movwf A1
0006 2010 00040 call FN_FUN1
0007 3002 00041 movlw 2
0008 00A0 00042 movwf A1
0009 2010 00043 call FN_FUN1
000A 0823 00044 movf FUN1,W
000B 0723 00045 addwf FUN1,W
000C 00A1 00046 movwf B1
000D 2804 00047 goto START
FN_FUN1
0010 0A20 00057 incf A1,W
0011 00A3 00060 movwf FUN1
0012 0008 00061 return
I ran into this when doing the SSP slave library. I can't speak to a fix, but the workaround per Hugh is using a script inside your function. So I believe your FUN1 would equal my RxBuffersize.
#script ;GCBasic treats AnyArray(1) as variable
RxBufferSize = BufferLen
if BufferLen = 1 then RxBufferSize = 2
#endscript
That is a bug with functions, which I've fixed in the latest update. I should have checked for it when I dealt with the similar bug in arrays.
The update is at http://gcbasic.sourceforge.net/newfiles/update.zip or http://gcbasic.sourceforge.net/newfiles/update-nochipdata.zip depending on what chip data files you already have installed. Download the first one if your chip data files are older than 27/9/2007, otherwise download the second one.