Page 1 of 1

I'm missing something fundamental here

Posted: Thu Jul 02, 2009 5:19 am
by Mistrel
I must be doing something very wrong here. Why doesn't this work?

Code: Select all

*This.String=@"Hello!"
Debug PeekS(*This) ;/ Works fine
Debug *This\s ;/ Errors here
It can't be missing the null byte otherwise PeekS() would fail.

This works fine:

Code: Select all

That.i=7
*This.Integer=@That
Debug PeekI(*This)
Debug *This\i

Re: I'm missing something fundamental here

Posted: Thu Jul 02, 2009 8:53 am
by Trond
Mistrel wrote:I must be doing something very wrong here. Why doesn't this work?

Code: Select all

*This.String=@"Hello!"
Debug PeekS(*This) ;/ Works fine
Debug *This\s ;/ Errors here
Because you're missing something fundamental! :D
What is *This.String? Is it a pointer? Yes.
Is it a pointer to string data? No!
Is it a pointer to a string variable? Yes!
What does @String do? Receive a pointer to the string variable? No!
@String (or @"String") receives a pointer to the string data.

*This.String is a pointer to a structure which contains a single string variable.
You set *This.String to point to some string data. It should point to a string variable.

A string variable is just a pointer which points to the string data.

PeekS() does not expect a pointer to a string variable. It expects a pointer to string data. That is why it works.

Code: Select all

StringPointer = @"Hello"
*This.String = @StringPointer
Debug PeekS(@*This\s)
Debug *This\s