The Byval keyword (placed before a passed variable) may be used in the context of Byref parameters and Byref function results, where it can be used to explicitly override the by-reference semantics in order to pass or assign a pointer as-is to a Byref parameter or function result.
But the same syntax used with Byval parameters and Byval function results is also allowed (no error neither warning from compiler).
These two syntaxes seem to work well also, but for the one only used in front of a Byval parameter ('Declare procedure_name(Byval As data_type)'), the behavior is slightly different:
- 'procedure_name(parameter_name)' : the copy-constructor is called, the explicit if exists,
- 'procedure_name(Byval parameter_name)' : the implicit copy-constructor is always called, even if an explicit exists.
That last behavior may be generator of bug if a simple memory allocation plus a shallow copy is not sufficient.
For example in case of virtuality use, the vptr of such an instance ('procedure_name(Byval parameter_name)') is baddly initialized.
I think the better should be to forbid the Byval keyword (placed before a passed variable) in the context of Byval parameters and Byval function results.
For more details and an example of aborting, see the forum at:
http://www.freebasic.net/forum/viewtopic.php?p=222101#p222101
http://www.freebasic.net/forum/viewtopic.php?p=222144#p222144
Since fbc version 1.10.0 , the 2 examples (from the 2 links above) produce a compile error.
C:.....\FBIDETEMP.bas(11) error 58: Type mismatch, at parameter 1 of UDT.constructor(as UDT) in 'PassByval(Byval u)'
C:.....\FBIDETEMP.bas(9) error 58: Type mismatch, at parameter 1 (
__FB_RHS__
) of UDT.constructor(as const UDT) in 'PassByval(Byval u)'Last edit: fxm (freebasic.net) 2024-03-20