Complex expression as:
Cast( Function (...) As ..., @f ) (...)
is often badly compiled in 64-bit, except with option '-exx'.
But such an expression, decomposed on two separated lines as:
Dim fcall As Function (...) As ... = Cast( Function (...) As ..., @f ) fcall (...)
is well compiled in 64-bits even without option '-exx'.
This following example works (without any warning):
-In 32-bit with gas and gcc, with or without option '-exx'.
-In 64-bit with option '-exx'.
Function f (Byval P As Integer Ptr) As Any Ptr Return P End Function Dim As Integer array(0) Print Cast(Function (() As Integer) As Any Ptr, @f)(array()) Sleep
But this example outputs warnings and it crashes as announced in 64-bit without option '-exx':
Command executed:
"D:\Users\T0003830\Documents\Mes Outils Personnels\FBIde0.4.6r4-FreeBASIC1.06.0.win64\fbc.exe" "D:\Users\T0003830\Documents\Mes Outils Personnels\FBIde0.4.6r4-FreeBASIC1.06.0.win64\FBIDETEMP.bas" -w pedanticCompiler output:
D:\Users\T0003830\Documents\Mes Outils Personnels\FBIde0.4.6r4-FreeBASIC1.06.0.win64\FBIDETEMP.c: In function 'main':
D:\Users\T0003830\Documents\Mes Outils Personnels\FBIde0.4.6r4-FreeBASIC1.06.0.win64\FBIDETEMP.c:71:26: warning: function called through a non-compatible type
void vr$5 = ((tmp$3)&F)( (struct $7FBARRAYIu7INTEGERE)&tmp$2$0 );
^
D:\Users\T0003830\Documents\Mes Outils Personnels\FBIde0.4.6r4-FreeBASIC1.06.0.win64\FBIDETEMP.c:71:26: note: if this code is reached, the program will abortResults:
Compilation successful
Generated executable: D:\Users\T0003830\Documents\Mes Outils Personnels\FBIde0.4.6r4-FreeBASIC1.06.0.win64\FBIDETEMP.exeSystem:
FBIde: 0.4.6
fbc: FreeBASIC Compiler - Version 1.06.0 (04-09-2017), built for win64 (64bit)
OS: Windows NT 6.1 (build 7601, Service Pack 1)
If we decompose the incriminated line:
Print Cast(Function (() As Integer) As Any Ptr, @f)(array())
in 2 distinct lines using a function pointer:
Dim fcall As Function (() As Integer) As Any Ptr = Cast(Function (() As Integer) As Any Ptr, @f) Print fcall(array())
This works also in 64-bit without option '-exx'.
For more information, see the forum from the post:
http://www.freebasic.net/forum/viewtopic.php?p=232120#p232120
For a still more complex syntax, compile with option '-exx' does not solve the problem, and worst, only 'gas' (32-bit) works, never 'gcc' (32-bit and 64-bit).
http://www.freebasic.net/forum/viewtopic.php?p=211700#p211700
http://www.freebasic.net/forum/viewtopic.php?p=211702#p211702
But after analysis, it seems that this behavior is a combination of this bug #854 with perhaps another impact of bug #844, because enclosing each line 'Swap ...' into a local scope block brings us back only to this bug #854.
Last edit: fxm (freebasic.net) 2017-05-21