Page 2 of 2

Posted: Wed Mar 22, 2006 5:58 pm
by Straker
ByVal = data

ByRef = pointer

Basically, ByRef (PB pointer) will change the value of the passed external variable. ByVal will not, respecting the parameter as a local variable only, and leaving the passed external variable unchanged.

In VB (and other languages), specifying ByRef tells the compiler to treat the parameter as a pointer, thats all.

Posted: Wed Mar 22, 2006 7:32 pm
by Karbon
In PB it is all about how you used the data passed into the function. A pointer is still data. If you treat it like a pointer in PB, it is one (more or less)..

So technically speak passing a pointer and passing int 12345 is the same thing as far as *what* gets passed - an integer. All AFAIK, IANAL, FYI, etc

Posted: Wed Mar 22, 2006 10:17 pm
by Dare2
Mostly ByVal = copy of data, ByRef = pointer or address of data. However aren't there some other things as well? Doesn't the type of variable also impact on things? Eg non-primitives using heap instead of stack, etc?

Posted: Thu Mar 23, 2006 6:00 am
by Yogi Yang
traumatic wrote:
Kale wrote:Am i missing something here. :?:
Don't know. :)



This is not a matter of VB (other languages allow you to chose how
to pass parameters as well **), it's a matter of design/concept/needs.


Using ByVal, only a copy of the parameter will be used inside the
procedure. This prevents the procedure from changing the passed
data. Values are being preserved.

(Using a copy obviously allocates memory when calling the procedure
and comes with a certain performance hit of course.)



With ByRef (PB's way) on the other hand you're passing a memory
location, thus allowing the procedure to change the passed data,
which may not always be wanted.





** think of C for example:

Code: Select all

void ByVal(yourStruct var);
void ByRef(yourStruct& var);
[/size]
This is apptly put.

I used the word VB as I know only Visual Basic and nothing else. I left C when I saw VB 2 and from then on I have never used any other language till date except AutoHotKey and WinBatch.

Re: A few VB touches....

Posted: Thu Mar 23, 2006 6:05 am
by Yogi Yang
Yogi Yang wrote:A large set for Functions for manuplating Strings like those in VB and more, Arrays & such collections features as implemented in VB.NET would be great to have in PB.
There should be implementation of almost all String Management functions like Left$, Right$, Mid$, ReverseStr, StringCompare, StringCovert (for converting between ANSI and UNICODE as well as for Case Conversion), etc. etc. etc.

I am learning VB.NET currently and like the features that are provided for Arrays and Collections. Implementing similar features would be a bonus for PB developers.

In fact there are many features in .NET Core Lib which are worth implementing as they will reduce a lot of error prone coding.....

Posted: Thu Mar 23, 2006 9:25 am
by blueznl
well, i still claim pure is using byval instead of byref, look at the pseudo code below:

Code: Select all

procedure x(byref a.l)   ; not possible in pure
  a = a+1
endprocedure

procedure y(*a.LONG)
  *a\l = *a\l + 1
endprocedure
perhaps the above illustrates it better

it's not that i'm claiming pure cannot do it, it does it very well, actually, but it's using byval instead of byref for regular parameters being passed

i'm not referring to the CONCEPT of modifying the variables, just to the implementation in purebasic :-)

Posted: Thu Mar 23, 2006 9:38 am
by traumatic
Sorry, no, we're talking about passing structures to procedures.
ByVal means (by definition) copying the params to the stack, which is
something PB definitely doesn't do. They're passed ByRef.