On 12 September 2010 17:12, Mike Caron <[email protected]> wrote: > On 9/12/2010 1:01 AM, Keith Gable wrote: >> >> On Sun, 2010-09-12 at 12:57 +1200, Ralph Versteegen wrote: >>> >>> C didn't have references. >> >> I thought that a reference in BASIC languages is the same thing as a >> pointer in C languages. In VB6, ByVal creates a copy of the object (I'm >> sure it does the same thing in FB), whereas ByRef is a pointer, even to >> the extent that C APIs that follow the standard calling convention that >> require pointers will work if you define the pointers as ByRef. Though >> that same API could be declared ByVal but then you use AddressOf when >> calling it.
VB6 calls it "AddressOf" instead of @ or &??? >> [This site][1] seems to reinforce this, at least for VB6. Are things >> different in FB? Just curious. >> >> [1]: http://www.cpearson.com/excel/byrefbyval.aspx > > No, you are correct. I will make a table: > > |------------------------------------------------| > |ALMOST EQUIVALENT THINGS | > |------------------------------------------------| > | BASIC | C | C++ | > |------------------+----------+------------------| > | BYREF | Pointers | References * | > |------------------+----------+------------------| > | BYREF as integer | int * | int & | > |------------------------------------------------| > > - BYVAL parameters are copies of the original, passed via stack. They can be > modified with no consequence (unless it's a UDT with pointers, since the > pointers will still point at the old data!) > > - BYREF parameters are pointers, but they cannot be reassigned. > > - Pointers are pointers (duh), but they CAN be reassigned. > > - References are aliases to the variables they reference. They cannot be > reassigned, and are effectively the same as the original variable. At first I thought C++ references and BYREF arguments were identical, however there's a difference. You can't pass a primitive data type temporary variable (such as a constant, eg. just passing '3') as a reference argument in C++, while you can in FB. In both languages, you can pass temporary structures by reference. _______________________________________________ Ohrrpgce mailing list [email protected] http://lists.motherhamster.org/listinfo.cgi/ohrrpgce-motherhamster.org
