Casting Pointers

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Stan.

Unless I missed it, there no way to cast pointers, seems PB is VERY
peeky about that ... ( I suppose this is related to the parsing/compilation
method ). As an old C programmer I really miss it !
Any suggestion ?

Stan


Learning and Love are what life is all about ... [ PB. registered user ]
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

What do you want to do exactly ?

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Stan.
What do you want to do exactly ?

Fred - AlphaSND
Something like :

*Byte_ptr.b

String_one.s = "xxx"

*Byte_ptr = () @String_one

TIA




Learning and Love are what life is all about ... [ PB. registered user ]
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.
Something like :

*Byte_ptr.b

String_one.s = "xxx"

*Byte_ptr = () @String_one
I don't quite understand what you're looking for, but could it possible be something like this:

Code: Select all

Structure chartype
  char.b
EndStructure

string.s="hello"
*byte_ptr.chartype=@string

For i=1 To Len(string)
  new_string.s+Chr(*byte_ptr\char)
  *byte_ptr+1
Next
MessageRequester("",new_string,0)
End
Hope it helps somewhat, if not perhaps a little further explaining of what 'casting' means might clear things for me.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

Yes, using a pointer (*pointer) and a structure like Pupil have do is the best way to do it. This is the equivalent to a '*(charbuffer) = x' in C.

Fred - AlphaSND
Post Reply