Revision history for KeyPgByrefFunction


Revision [22574]

Last edited on 2019-02-26 08:22:25 by fxm [Suppressed reference to fbc version 0.90]
Additions:
**Note:** On the left-hand side of an assignment expression using the '##=##' symbol, the result of the function (returned by reference) must be enclosed in parentheses when the function calls one single argument, in order to solve the parsing ambiguity. '##=>##' can be used for assignments, in place of '##=##', same as for initializers, allowing to avoid parsing ambiguity (without parentheses). As for the arguments list, it should always be surrounded with parentheses even if empty.
Deletions:
**Note:** On the left-hand side of an assignment expression using the '##=##' symbol, the result of the function (returned by reference) must be enclosed in parentheses when the function calls one single argument, in order to solve the parsing ambiguity. From fbc version 0.90, '##=>##' can be used for assignments, in place of '##=##', same as for initializers, allowing to avoid parsing ambiguity (without parentheses). As for the arguments list, it should always be surrounded with parentheses even if empty.


Revision [22354]

Edited on 2018-08-13 06:07:55 by fxm [Updated third example]
Additions:
'' This variable-length string will transit by reference (input and output), no copy will be created.
f1( ) = f1( ) & "efgh"
'' The enclosing parentheses are required here on the left-hand side.
( f2( s ) ) = f2( s ) & "ijkl"
'' The enclosing parentheses are not required here on the left-hand side.
f2( s ) => f2( s ) & "mnop"
Deletions:
f1( ) &= "efgh"
'' At time of writing, the enclosing parentheses are required here.
( f2( s ) ) &= "ijkl"


Revision [21291]

Edited on 2016-04-01 08:05:30 by fxm [Added link to BYREF (variables)]
Additions:
- ##[[KeyPgByrefVariables|Byref (variables)]]##


Revision [20070]

Edited on 2016-02-10 15:55:08 by DkLwikki [Update link format]
Additions:
[[KeyPgFunction|Function]] //name// ( //parameter-list// ) **Byref** [[KeyPgAs|As]] //[[DataType|datatype]]//
Return I
Return J
- [[ProPgReturnValue|Returning values]]
- ##[[KeyPgByref|Byref (parameters)]]##
Deletions:
[[KeyPgFunction Function]] //name// ( //parameter-list// ) **Byref** [[KeyPgAs As]] //[[DataType datatype]]//
Return I
Return J
- [[ProPgReturnValue Returning values]]
- ##[[KeyPgByref Byref (parameters)]]##


Revision [16958]

Edited on 2013-09-21 20:31:54 by CountingPine [Formatting]
Additions:
**Note:** On the left-hand side of an assignment expression using the '##=##' symbol, the result of the function (returned by reference) must be enclosed in parentheses when the function calls one single argument, in order to solve the parsing ambiguity. From fbc version 0.90, '##=>##' can be used for assignments, in place of '##=##', same as for initializers, allowing to avoid parsing ambiguity (without parentheses). As for the arguments list, it should always be surrounded with parentheses even if empty.
Deletions:
**Note:** On the left-hand side of an assignment expression using the '=' symbol, the result of the function (returned by reference) must be enclosed in parentheses when the function calls one single argument, in order to solve the parsing ambiguity. From fbc version 0.90, '=>' can be used for assignments, in place of '=', same as for initializers, allowing to avoid parsing ambiguity (without parentheses). As for the arguments list, it should always be surrounded with parentheses even if empty.


Revision [16955]

Edited on 2013-09-20 14:05:55 by FxMwikki ['=>' can now be used for assignments, in place of '=', in order to avoid parsing ambiguity]
Additions:
**Note:** On the left-hand side of an assignment expression using the '=' symbol, the result of the function (returned by reference) must be enclosed in parentheses when the function calls one single argument, in order to solve the parsing ambiguity. From fbc version 0.90, '=>' can be used for assignments, in place of '=', same as for initializers, allowing to avoid parsing ambiguity (without parentheses). As for the arguments list, it should always be surrounded with parentheses even if empty.
Deletions:
**Note:** On the left-hand side of an assignment expression, the result of the function (returned by reference) must be enclosed in parentheses when the function calls one single argument (an arguments list, even if empty, should be surrounded with parentheses).


Revision [16947]

Edited on 2013-09-14 03:51:49 by FxMwikki [Complemented the first example with the returned reference reading before writing]
Additions:
Print min( A , B )


Revision [16944]

Edited on 2013-09-08 17:04:08 by CountingPine [(Formatting)]
Additions:
Functions with ##**Byref**## result should not return local variables from the function, because they will be destroyed upon returning from the function, invalidating any pointer or reference to them. To help with writing safe code, the compiler will show an error message when a local variable is used with ##Function = //x//## (or ##//name// = //x//##) assignments and ##Return //x//## statements.
Deletions:
Functions with ##**Byref**## result should not return local variables from the function, because they will be destroyed upon returning from the function, invalidating any pointer or reference to them. To help with writing safe code, the compiler will show an error message when a local variable is used with ##Function = x## (or ##//name// = x##) assignments and ##Return x## statements.


Revision [16941]

Edited on 2013-09-08 10:13:01 by FxMwikki [Improved comment for the second example (returning a string literal by reference)]
Additions:
'' This string literal (because statically allocated in memory) will be returned by reference, no copy will be created.
Deletions:
'' This string will be returned by reference, no copy will be created.


Revision [16940]

Edited on 2013-09-08 03:49:54 by FxMwikki [Added simpler code for the first example]
Additions:
'' The smallest integer will be returned by reference, no copy will be created.
Deletions:
'' The smallest integer variable will be returned by reference, no copy will be created.


Revision [16939]

Edited on 2013-09-08 03:05:36 by FxMwikki [Added simpler code for the first example]
Additions:
End If
Deletions:
End If


Revision [16938]

Edited on 2013-09-08 02:39:47 by FxMwikki [Added simpler code for the first example]
Additions:
{{fbdoc item="filename" value="examples/manual/procs/byref-result4.bas"}}%%(freebasic)
Function min( Byref I As Integer , Byref J As Integer ) Byref As Integer
'' The smallest integer variable will be returned by reference, no copy will be created.
If I < J Then
Return I
Else
Return J
End If
Dim As Integer A = 13, B = 7
Print A, B
min( A , B ) = 0
Print A, B


Revision [16674]

Edited on 2013-03-23 18:05:40 by FxMwikki [Added in note that parentheses should surround an argument list even if empty]
Additions:
**Note:** On the left-hand side of an assignment expression, the result of the function (returned by reference) must be enclosed in parentheses when the function calls one single argument (an arguments list, even if empty, should be surrounded with parentheses).
Deletions:
**Note:** On the left-hand side of an assignment expression, the result of the function (returned by reference) must be enclosed in parentheses when the function calls one single argument.


Revision [16646]

Edited on 2013-03-10 05:12:58 by FxMwikki ['Byref returns' can also be used by operators to return references]
Additions:
Operators (member or global), when used as functions, have also the capability to return results by reference, by using the same syntax.


Revision [16615]

Edited on 2013-03-02 14:12:38 by FxMwikki [Added the third method of returning from a function]
Additions:
Functions with ##**Byref**## result should not return local variables from the function, because they will be destroyed upon returning from the function, invalidating any pointer or reference to them. To help with writing safe code, the compiler will show an error message when a local variable is used with ##Function = x## (or ##//name// = x##) assignments and ##Return x## statements.
Deletions:
Functions with ##**Byref**## result should not return local variables from the function, because they will be destroyed upon returning from the function, invalidating any pointer or reference to them. To help with writing safe code, the compiler will show an error message when a local variable is used with ##Function = x## assignments and ##Return x## statements.


Revision [16589]

Edited on 2013-02-06 22:32:51 by CountingPine [... at least until we solve the ambiguity issue.]
Additions:
'' At time of writing, the enclosing parentheses are required here.
Deletions:
'' The enclosing parentheses are mandatory.


Revision [16588]

Edited on 2013-02-06 15:19:17 by FxMwikki [Added the case when it is mandatory of enclosing the function result within parentheses]
Additions:
**Note:** On the left-hand side of an assignment expression, the result of the function (returned by reference) must be enclosed in parentheses when the function calls one single argument.
'' The enclosing parentheses are mandatory.


Revision [16586]

Edited on 2013-02-04 13:05:43 by FxMwikki [Added an example of function return-byref cascading]
Additions:
{{fbdoc item="filename" value="examples/manual/procs/byref-result3.bas"}}%%(freebasic)
Function power2( Byref _I As Integer ) Byref As Integer
_I *= _I
'' This integer will be returned by reference, no copy will be created.
Function = _I
End function
Dim As Integer I = 2
power2( power2( power2( I ) ) ) '' Function return-byref cascading is equivalent to ((I*I)*(I*I))*((I*I)*(I*I)) = I^8
Print I


Revision [16572]

Edited on 2013-02-04 00:04:30 by CountingPine [Example 1: return a const zstring]
Additions:
function f( ) byref as const zstring
Deletions:
function f( ) byref as zstring


Revision [16571]

Edited on 2013-02-03 13:51:19 by FxMwikki [Added another example that proves the return by reference (variable-length string)]
Additions:
Function f1( ) ByRef As String
Function f2( ByRef _s As String ) ByRef As String
Deletions:
Function f1( ) Byref As String
Function f2( Byref _s As String ) Byref As String
Print s%%


Revision [16570]

Edited on 2013-02-03 08:26:53 by FxMwikki [Added another example that proves the return by reference (variable-length string)]
Additions:
{{fbdoc item="filename" value="examples/manual/procs/byref-result2.bas"}}%%(freebasic)
Dim Shared As String s
s = "abcd"
Print s
Function f1( ) Byref As String
'' This variable-length string will be returned by reference, no copy will be created.
Function = s
End Function
Function f2( Byref _s As String ) Byref As String
'' This variable-length string will be returned by reference, no copy will be created.
Function = _s
End Function
f1( ) &= "efgh"
Print s
( f2( s ) ) &= "ijkl"
Print s%%


Revision [16565]

Edited on 2013-01-28 16:20:02 by CountingPine [Monospace keyword usage]
Additions:
Causes the function result to be returned by reference, rather than by value. A function returning ##**Byref**## will return the address of a variable, instead of making a copy like when returning by value. This allows the caller of the function to modify the variable which the function result points to.
If ##**Byref**## is not specified, the default is to return the function result by value.
Functions with ##**Byref**## result should not return local variables from the function, because they will be destroyed upon returning from the function, invalidating any pointer or reference to them. To help with writing safe code, the compiler will show an error message when a local variable is used with ##Function = x## assignments and ##Return x## statements.
Deletions:
Causes the function result to be returned by reference, rather than by value. A function returning **Byref** will return the address of a variable, instead of making a copy like when returning by value. This allows the caller of the function to modify the variable which the function result points to.
If **Byref** is not specified, the default is to return the function result by value.
Functions with **Byref** result should not return local variables from the function, because they will be destroyed upon returning from the function, invalidating any pointer or reference to them. To help with writing safe code, the compiler will show an error message when a local variable is used with ##Function = x## assignments and ##Return x## statements.


Revision [16564]

Edited on 2013-01-28 15:22:50 by DkLwikki [Link to ProPgReturnValue]
Additions:
- [[ProPgReturnValue Returning values]]


Revision [16556]

Edited on 2013-01-28 14:31:11 by DkLwikki [typo]
Additions:
Specifies that a function result is returned by reference
Deletions:
Specifies that a function result be returned by reference


Revision [16553]

Edited on 2013-01-28 14:27:32 by DkLwikki [Add new page for BYREF function results]
Additions:
{{fbdoc item="title" value="BYREF (function results)"}}----
Deletions:
{{fbdoc item="title" value="BYREF (function result)"}}----


Revision [16551]

Edited on 2013-01-28 14:25:55 by DkLwikki [Add new page for BYREF function results]
Additions:
[[KeyPgFunction Function]] //name// ( //parameter-list// ) **Byref** [[KeyPgAs As]] //[[DataType datatype]]//
Deletions:
[[KeyPgFunction Function]] //name// ( //parameter-list// ) **Byref** [[KeyPgAs As]] [[DataType datatype]]


Revision [16550]

The oldest known version of this page was created on 2013-01-28 14:25:21 by DkLwikki [Add new page for BYREF function results]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode