Post Reply 
Sharp BASIC anomaly
01-19-2023, 12:53 AM
Post: #1
Sharp BASIC anomaly
I stumbled upon something a bit strange playing around with few of my Sharp pockets.

The following code:

Code:
10 P$ = "PASSWORD"
20 IF P$ = "PASSWORD" THEN PRINT "CORRECT"

Executes correctly on PC-1500, however it fails on both EL-5500II and PC-G850VS. It appears the later two only recognize first seven characters in a string, despite being newer, so only the following works:

Code:
10 P$ = "PASSWORD"
20 IF P$ = "PASSWOR" THEN PRINT "CORRECT"

This might be a well-known fact, but figured I'd share as I found it interesting...
Find all posts by this user
Quote this message in a reply
01-19-2023, 06:45 PM (This post was last modified: 01-19-2023 06:50 PM by Dave Britten.)
Post: #2
RE: Sharp BASIC anomaly
Correct, in most Sharps, the variables A-Z share the same (fixed) memory locations as A$-Z$, and thus the space for a float/numeric variable ends up being big enough to hold strings of 7 characters. (8 bytes each in most models, I believe.)

Later models (I think this includes your EL-5500II and PC-G850) can DIM larger strings, but they have to be declared as arrays (which can have just a single element if you wish).

e.g. DIM R$(0)*26 gives you an array R$ with one element (subscript 0) that will hold a string up to 26 characters in length. DIM NM$(10)*10 gives you an array with 11 elements (subscripts 0-10) that hold 10 characters each.

EDIT: And if you use "simple variables" (i.e. two-character variable names that are allocated dynamically upon use), those hold strings up to 16 characters in length. AA$="PASSWORD12345678" should work as expected.

The PC-1500 has a more traditional BASIC that dynamically allocates space for strings depending on length.
Visit this user's website Find all posts by this user
Quote this message in a reply
01-19-2023, 07:43 PM
Post: #3
RE: Sharp BASIC anomaly
Thanks for a great explanation Dave, makes sense now!
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)