Pointers in BBC BASIC (on RISC OS) I finally managed to get it working... so this is a quick note to myself, in case I forgot. I intend to use it mainly to get some kind of structures working, since BBC BASIC on RISC OS doesn't have structs (unlike windows version...). Basically will reserve a zone of memory and divide it according the needs. Maybe (surely) exists a better method, but this is how I thought it right now. For example, let's say we want to reserve a zone of memory in which we'll store an integer and a pointer to a string. Thus, we'll need 32 bit for the integer (4 bytes) and another 4 bytes for the pointer. [I have yet to check the size of the pointer var, but I think 4 bytes is ok] So, we'll reserve 2 bytes of memory for this mememory block. Also we reserve 10 bytes for a string of 10 chars. ` DIM mb% 7` -> bytes 0 through 7
` DIM sb% 9` Now we'll allocate values: ` !mb% = 1234`
` $sb% = "Chars str."` The `!` is used for integers indirection and `$` for string indirection (also for bytes indirection). `!mb%` references the first byte in memory block, which is an integer represented on 32 bits. `$sb%` references the starting address of the string [`$(sb%+1)` references the second byte = the second character of the string and so on] Now, on the second byte of our memory block we'll put the address of the string: ` !(mb%+4) = sb%` For testing the results, we'll have to display something on the screen: ` PRINT "At address ";mb%;" we have an integer: ";!mb%`
` PRINT "At address ";mb%+4;" we have the string address: ";!(mb%+4)`
` PRINT "At address ";\!(mb%+4);" we have the string: ";%(!(mb%+4))` All seems ok now; will try to experiment more and find some more info about the subject. Note: For floating point indirection, the '|' symbol is used. For BBC BASIC V, 5 bytes are used and for BBC BASIC VI, 8 bytes are used. tags: RISC-OS, programming, pointers