Q(uick)BASIC Function: SSEGADD
Quick View
SSEGADD
A function that returns the far address of stringvariable& (both segment and offset)
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- SSEGADD(stringvariable$)
Description/Parameter(s)
stringvariable$ | The string variable for which you want to find an address. It can be a simple string variable or a single element of a string array. You cannot use fixed-length string arguments. |
SSEGADD returns the far address of stringvariable& (both segment and offset). |
This function is typically used in mixed-language programming to obtain far addresses before passing far strings to procedures written in other languages.
Usage Notes
- The SSEGADD function combines the segment and offset information into one long integer (4 bytes).
- SSEGADD usually is used with far strings but can also be used with strings stored in DGROUP.
- The offset of a string can be found with the SADD function; the segment of a string can be found with the SSEG function.
Example
This example uses the SSEGADD function to obtain the BASIC string address of a string used by a C procedure. The BASIC program calls the printmessage C procedure which, in turn, calls BASIC to obtain the string address.
Note: To run this program, you must first compile the C procedure (shown below in remarks) and incorporate it in a Quick library or link it to the compiled BASIC program.
DEFINT A-Z
DECLARE SUB printmessage CDECL (BYVAL farstring AS LONG)
'Create the message as an ASCIIZ string, as required by the C printf
'function.
a$ = "This is a short example of a message" + CHR$(0)
'Call the C procedure with pointers.
CALL printmessage(SSEGADD(a$))
'/* C Routine printmessage */
'/* Prints a BASIC far string on the screen.*/
'
'#include <stdio.h>
'
'/* Define a procedure which inputs a string far pointer */
'void printmessage (char far *farpointer)
' {
' /* print the string addressed by the far pointer */
' printf( "%s
", farpointer);
' }
'
See also: