Should Address(variable) work with overloaded prototypes where a value or address can be accepted?

Got a couple of class methods , overloaded but one is defined as a pass "by addres"s the other is defined as pass “by value”.

Now the compiler already throws an error message with entities passed by value

Syntax Error: Procedure doesnt belong to module: CLASSNAME.PROCEDURE

I wouldnt have expected this message but the help docs isnt clear if entities are passed “by address” or “by value” if such a thing could exist, the help doc examples showing FILE are not really clear.

Anyway when I call a class with every datatype & entity overloaded so there is 1 “by address” method and 1 “by value” method (even though in procedure overloading all datatypes by values are treated the same so probably best to just use an ? (any) ), I found when calling the class using address(loc:byte) its treated as an any “by value”!

Shouldnt Address() work with the runtime recognising its being by passed “by address” instead of passing the variable address as “by value”?

I know technically Address() is working as expected, but its not working with the runtime parameters, or am I wrong in this instance?

Open to opinions! :grinning:

TIA

!*Key and *Index are the same entities

Code

App Window Byte Button Take Accepted.

Case Upper(Loc:Type)
OF 'STRING'
    Message(CallClass:GetParam.DataTyperS(Address(Loc:Byte)))
OF 'LONG'
    Message(CallClass:GetParam.DataTyperL(Address(Loc:Byte)))
Else
    Message('Error')
End

Class GetParam

IS_DTL:Byte                    Equate(04h)
IS_DTS:Byte           Equate('_BYTE_')

DataTyperS           Procedure(*Byte pType),String
!DataTyperS           Procedure(Byte pType),String              !Procedure Overloading Rule 6 - Using ? (an ANY)
DataTyperL           Procedure(*Byte pType),Long
!DataTyperL           Procedure(Byte pType),Long                !Procedure Overloading Rule 6 - Using ? (an ANY)


GetParam.DataTyperS                  Procedure(*Byte pType)
    Code
    Return IS_DTS:Byte

!GetParam.DataTyperS                  Procedure(Byte pType)         !Procedure Overloading Rule 6 - Using ? (an ANY)
!    Code
!    Return IS_DTS:Byte

    GetParam.DataTyperL                  Procedure(*Byte pType)
        Code
        Return IS_DTL:Byte

    GetParam.DataTyperL                  Procedure(Byte pType)         !Procedure Overloading Rule 6 - Using ? (an ANY)
        Code
        Return IS_DTL:Byte

if you are passing address(whatever) then you are passing by value as address() will return a number.

the called procedure is passed a number and it has no magical insight that that number happens to be an address in memory.

so to pass by address (or “by reference” as it is sometimes called) have a prototype with * before the parameter type. eg. *STRING and then simply pass a string field by its name myFunc(myString).

note you cannot then put in anything like myFunc(‘hello’) or myFunc(clip(myString)) as then you are passing by value.

of course you can overload a function name to provide a version with passed by value and another passed by address/reference. However if working in the IDE it is not easy to do overloading so usually I do this in classes etc.

and talking of classes, if you pass a class then it is automatically passed by address/reference so

myFunc procedure(myclass xx)

and

myFunc procedure(*myclass xx)

are the same.

hth

Geoff R

I understand this, but I was expecting more from the runtime, that was all.

I would have thought you’d get an ambiguous prototype error between some of those prototypes.

With a STRING, you have to be careful about simply passing the ADDRESS(). The size of the memory used by &STRING is 8 bytes. 4 bytes for the ADDRESS, and an additional 4 bytes for the SIZE.

If you simply pass the ADDRESS() of that string, you’re losing the size. Now you have a string without a length.

If the length is known, you can incorporate that into your &= assignment by separating the values with a colon.:

MyStringRef &= (MyAddress) & ‘:’ & (MySize)

Thats what I’ve found out today.