[Implemented] A few VB touches....

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Straker
Enthusiast
Enthusiast
Posts: 701
Joined: Wed Apr 13, 2005 10:45 pm
Location: Idaho, USA

Post 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.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post 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
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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?
@}--`--,-- A rose by any other name ..
Yogi Yang
Enthusiast
Enthusiast
Posts: 107
Joined: Sun Dec 11, 2005 2:19 pm

Post 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.
Yogi Yang
Enthusiast
Enthusiast
Posts: 107
Joined: Sun Dec 11, 2005 2:19 pm

Re: A few VB touches....

Post 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.....
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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 :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post 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.
Good programmers don't comment their code. It was hard to write, should be hard to read.
Post Reply