Asc bug?

Discussion specific to the ZX-1281 and ZX-1280 microcontrollers as well as the ZX-1281 and ZX-1280 Dev Boards.
Post Reply
deadmm
Posts: 3
Joined: 17 March 2006, 6:37 AM
Location: Cambridge, UK

Asc bug?

Post by deadmm »

Hi Folks

While idling away the New Year I've come across this, distilled down from something a tad more complex:

Code: Select all

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
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Asc bug?

Post by dkinzer »

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.
- Don Kinzer
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Asc bug?

Post by dkinzer »

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.
- Don Kinzer
Post Reply