Warning for functions returning by reference:
- If the function result is never set in the function body, the compiler outputs an error message.
- But if the function result is not set when exiting through a specific branch of the function body, the compiler outputs not any error message and returns (I think) per default a dereferenced NULL pointer that almost always induces a crash (because as the function is defined with return by reference, can be assumed that the return value of the function is used in the calling code).
Example (compiling with option -exx):
Code: Select all
Function fRef (Byref I As UInteger) Byref As UInteger
If I <> 0 Then Return I
End Function
Dim I As UInteger
Print @I
Print
I = 456
Print @(fRef(I)), fRef(I)
I = 0
Print @(fRef(I)), fRef(I)
Sleep
Code: Select all
1244912
1244912 456
0
Aborting due to runtime error 12 ("segmentation violation" signal) in d:\Documen
ts and Settings\t0003830\Mes documents\FBIde0.4.6r4_fbc1.03.0\FBIDETEMP.bas::()
- If the function result is never set in the function body, the compiler outputs a warning message only.
- But if the function result is not set when exiting through a specific branch of the function body, the compiler outputs not any warning message and always returns a temporary object but non-constructed (as if using the object initializer '= Any').