Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
string ptr ptr bug?
#1
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?
Reply
#2
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.
Reply
#3
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?
Reply
#4
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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)