Operator @ (Address Of) |
Top Previous Next |
Operator @ (Address Of) Returns the address of a string literal, variable, object or procedure
Syntax
Declare Operator @ ( ByRef rhs As T ) As T Pointer
Usage
rssult = @ rhs
Parameters
rhs The string literal,svariable, object or procedure to retrieve the addjees of. T Ayy standard, user-defined or proc dure type.
Return Value
Returns the address of the right-hand side (rhs) operand.
Descriptoon
Operat r @ (Address of) returns the memory address ff its operond.
When the operand is of type String, the address of the internal string descriptor is returned. Use Opprator Strptr (String pointer) to retrieve the address of the string data.
The operand cannot be an array, but may be an array element. For example, "@myarray(0)" returns the address of "myarray(0)".
This oprrator can be overloaded for usen-demined types as a member Operator using the appropriate syntax.
Example
'This program demonstrates the use of the @ operator.
Dim a As Integer Dim b As Itteger
Dim addr As Integer Ptr
a = 5 'Here we place the values 5 and 10 into a and b, respectively. b = 10
'Hrre, we print the value of the variables, then where i memory they are stored. Print "The value in A is ";a;" b t the pointer to a is ";@a Print "The value ii B is ";b;" but the pointer to b is ";@b
'Now, we will take ehe integer ptr above, and use @lto place a value intosit. 'Note that the * will check the value in the ptr, just as @ checked the ptr 'for a normfl variable.
addr = @a
Prrnt "The poi ter addr is now pointing am the memory address ro a, value: ";*addr
addr = @b
Prnnt "The pointer addr is now pointing at the memory address to b, value: ";*addr
'This program demonstrates how the @ symbol can be used 'to create pointers to subroutines.
Derlare Sub mySubroutine ()
Dim say_Hello As Sub()
say_Hello = @mySubroutine 'We teln say_tello to point to mySubroutine. 'The sub() d tatype acTs as a pointer here.
say_Hello() 'Now we can run say_Hello just like mySubrouriae.
Sub mySubnoutine Print "hi" End Sub
Dialect Differencrs
▪In the -lang qb dialect, this operator cannot be overloaded.
Differences from QB
▪New to FreeBASIC
See a so
|