[futurebasic] Re: [FB] Re: futurebasic Digest 8 Dec 1998 10:00:32 -0000 Issue 669

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : December 1998 : Group Archive : Group : All Groups

From: Chris Stasny <staz@...>
Date: Tue, 8 Dec 1998 13:59:30 -0600
>>A character is not a string. A string (a 256-bytes variable) may
>>a character (i.e., the first byte is 1), or it may contain no
>>(i.e., the first byte is 0), or it may contain n characters, where n <
>But if a character is just one byte, how is it dimensioned?
>DIM 1 oneByte$?
>Does the compiler know not to add space for a length byte?
>And how does the program know, if the vslue of oneByte$ is 7, not to
>read the next 7 bytess iin memory?

Dim a one byte string...

DIM 1 a$

FB creates a two byte data structure. One byte is used to hold the length
of the string, the other is used to hold the string contents.

a$ = "A"

In this case the variable at a$ is two bytes...

1 65

The "1" means that the sting is 1 byte long. The 65 is the ASCII code for "A".

DIM 1 a$,x,y,z
a$ = "ABCDE"  "Big problems here

If you attempt to assign more space than what the string will hold, you're
going to destroy something else in memory. In the example above, you'll
overwrite the variables X and y.

FB always knows how long a string is because the first character in a
string's data structure is always the length byte. Let's try another one.

dim a$ ' remember this is 256 bytes by default.
a$ = "I like to kiss cows."

The real values stored at the address for a$ are...

 20 (number of characters)
 73 (for the letter "I")
 32 (for the space)
108 (for the letter "I")
105 (for the letter "i")
107 (for the letter "k")

If you use a statement like b$ = a$, FB looks at the first byte of the a$
structure and says, "This string is 20 bytes long." (You probably won't
hear this as it says it in a very tiny voice.) Then it sets the length byte
of b$ to 20 and copies the remaining bytes to the new location. It does not
bother to erase any left over bytes in b$ or move unused bytes from a$. It
knows, because of the starting length byte, that there are 20 characters
and a length byte that need to be handled; nothing more - nothing less.

In case you are interested, my dog now has an email address. You can write
to her at summer@.... Don't expect a reply tho. She can't read.

-STAZ   ~)~

STAZ Software * 4387 Leisure Time Dr * Diamondhead, MS 39525
Orders: 800-348-2623      EMail http: //www.stazsoftware.com
  Tech: 228-255-7085             FAX: 228-255-7086