Qbasicnews.com

Full Version: string ptr ptr bug?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Anonymous

hi

i was experimenting with string pointers, and thought, hey, since regular strings can be accessed like pointers now, why not try it with a string ptr. so, heres the code

Code:
Dim o As string Ptr

o = CAllocate(3 * Len(String))

o[0] = "just text"
o[1] = "chop"


? o[0]
? o[1]
? o[1][0]
? o[1][1]


youll see when you run it that o[1][0] returns the ASCII value of the letter "c" and [1][1] the ASCII of h. is this the way its supposed to be? shouldnt they return the characters, and not the ascii values?
Yeah, it's correct, string indexing returns the character (an unsigned byte), returning a string would slow it down at a point that it wouldn't be better than using MID$().

String indexing was added to speed up loops and to eliminate the strptr()'s or sadd()'s calls.

Anonymous

wow i didnt know that thanks

btw youre my hero :D


edit: asc() with a (literal?) string like asc("h") will evaluate to a number at compile time, right? so you could just use indexing with asc like that? "if thing$[2] = asc("j") " and still get speed increase right?
Yeah, ASC() when used with string literals (incl. expressions) will be evaluated at compile-time to an numeric literal, you could also use const CHAR_A = asc( "A" ) ... if( s[i] = CHAR_A ) ... etc