Code: Select all
void myfunc(int *x, int *y)
{
(*x)++;
(*y)++;
Code: Select all
myfunc(&x, &y);
Code: Select all
void myfunc(int *x, int *y)
{
(*x)++;
(*y)++;
Code: Select all
myfunc(&x, &y);
Isn't it similar easy in Pure Basic:PBJim wrote: Thu Feb 22, 2024 9:44 am Is there an easier method, such as the way it can be done more straightforwardly in C that doesn't require anything more than the pointer
Code: Select all
Procedure myfunc(*x.Integer, *y.Integer)
*x\i + 1
*y\i + 1
EndProcedure
Define a.i = 2, b.i = 5
myfunc(@a, @b)
Debug a
Debug b
Thanks, I appreciate the example, that's in fact considerably easier than the method I've been using. I've always used the method at the below link. It requires the variable being passed into the procedure also to have been defined with a structure, in addition to the structure within the procedure. It has been fairly labourious work, because I've converted existing code to return values by ref.
Thank you Tenaja, I see what you mean. For strings, it's still not quite so straightforward then. Ah well, worth a try. Thanks both for the replies.Tenaja wrote: Thu Feb 22, 2024 7:41 pm (I think) that method with a string is used because a string is already a pointer, and when you call a proc with a string argument, by default it copies the string prior to sending. That is a workaround specific to strings to send the string address.
Code: Select all
;-TOP by mk-soft
; String ByRef
Procedure MyFunction(var1, var2, *sResult.string)
*sResult\s + Str(var1 + var2)
ProcedureReturn Len(*sResult\s)
EndProcedure
Define sVar.String ; <- pre defined pb structure for string
Define len
sVar\s = "Result = "
len = MyFunction(100,100, @sVar)
Debug "String Len = " + len
Debug sVar\s