|
|
| Author |
Message |
deadmm
Joined: 17 Mar 2006
Posts: 3
Location: Cambridge, UK
|
|
Posted: 05 January 2009, 17:38 PM Post subject: Asc bug? |
|
|
Hi Folks
While idling away the New Year I've come across this, distilled down from something a tad more complex:
| Code: |
sub main()
Dim s as String
Dim b as Byte
dim i as byte
s = "Howdy"
b = asc(s)
debug.print b
debug.print
b=asc(s,1)
debug.print b
b=asc(s,2)
debug.print b
debug.print
for i = 1 to 2
b=asc(s,i)
debug.print b
next
end sub
. |
On my Zx1280 this produces:
ZBasic v2.6.3
72
0
0
72
111
in other words a directly entered index in Asc(string, index) doesn't work but a variable does.
I presume (perhaps dangerously) it's not meant to work that way
Mal |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR
|
|
Posted: 05 January 2009, 18:42 PM Post subject: Re: Asc bug? |
|
|
| deadmm wrote: | | I presume (perhaps dangerously) it's not meant to work that way | Indeed not. The output is the result of a code generation optimization problem that has now been corrected.
When the compiler can determine both the string content and the specified index (if any) at compile time it may substitute the resultant value instead of generating the code to effect the function call. There was a coding error in the compile-time evaluation of the index value that caused the compiler to conclude that the result would be zero, hence the observed output. |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR
|
|
Posted: 06 January 2009, 19:52 PM Post subject: Re: Asc bug? |
|
|
| dkinzer wrote: | | The output is the result of a code generation optimization problem that has now been corrected. | The compiler version v2.6.9 contains a correction for this issue. You can download the full installer or just the compiler via the Downloads Page. |
|
| Back to top |
|
 |
|