Please enable JavaScript to view this site.

A-Shell 6.5 Development Notes

New opcode DCOP_DEREF (4) "dereferences" a pointer to return the value pointed to. Using the getstring() function in the previous example, if it was called with the parameter signature "p" instead of ">", to get the address directly, you could then get the value as follows:

map1 buffer,s,0

map2 address,b,4

 

dlctl.opcode = DCOP_CALL

xcall DYNLIB, dlctl, "getstring(p)v", address   ! get ptr into address

 

dlctl.opcode = DCOP_DEREF

xcall DYNLIB, dlctl, address, buffer  ! copy string pointed to by address

                                      ! into buffer

 

This can be useful in dealing with functions that return a structure containing pointers to strings, rather than the strings themselves. But any time you are dealing with direct pointers like this, you run the risk of a segmentation fault if there is any discrepancy between the expected and actual parameters or behavior of the underlying function.