a perfectly fine working single line Macro (a #Define), in FBC 64bit = all OK, however, in FBC 32bit:
Executable returns wrong results ... I suspect it's (once again) the use of Integer (behind the scenes)!FBC 32 wrote:Macro_vs_Union.bas(26) warning 33(0): Shift value greater than or equal to number of bits in data type
Make done
Equally no problem is the used Union! (both versions of compiler)
This issue can't be forced, even with: CULngInt(...whatever), or, Cast(ULongInt, ...whatever)
Just to make things clear: the Function mk64() works perfectly, in both compiler versions!
It's the #Define mk64_() that has the problem. Is there any way to force its result to ULongInt?
Then the shift by 32 should work ...
see example code below:
Code: Select all
' Macro_vs_Union.bas -- 2017-03-21, by MrSwiss
Union UI_64 ' little endian!
As ULongInt UI64
Type
As ULong hi32
As ULong lo32
End Type
End Union
Dim As UI_64 cc64
With cc64 ' little endian!
.hi32 = &hCCDDEEFF
.lo32 = &h8899AABB
End With
' End Union
' single line MACROS, instead of Union
' Function mk64() needed for FBC 32 (now also used for FBC 64)
Declare Function mk64( ByVal As ULong, ByVal As ULong) As ULongInt
#Define mk64_(l,h) ( h Or l Shl 32 ) ' OK: FBC 64 -gen GCC | NOK: FBC 32 -gen GAS
#Define Hi32(ll) ( ll And &hFFFFFFFF ) ' getter - high 32bit
#Define Lo32(ll) ( ll Shr 32 ) ' getter - low 32bit
'Dim As ULongInt tt = mk64_(cc64.lo32, cc64.hi32) ' described error FBC 32 / OK in FBC 64
Dim As ULongInt tt = mk64(cc64.lo32, cc64.hi32) ' using Union's values + set Function
' End Macro's
Width 80, 25
Print : Color 10
Print "using the UNION:"
Print String(16, "-")
Print "Union - LO32: "; Hex(cc64.lo32, 8)
Print "Union - HI32: "; Hex(cc64.hi32, 8)
Print
Print "Union - cc64: "; Hex(cc64.UI64, 16)
Print : Color 15
' ----------------------
Print String(60, "~") ' screen delimiter
' ----------------------
Print : Color 11
Print "using the MACROS/Function:"
Print String(26, "-")
Print "ULL 64bit: "; Hex(tt, 16)
Print
Print "UL - HI32: "; Hex(Hi32(tt), 8) ' using get Macro
Print "UL - LO32: "; Hex(Lo32(tt), 8) ' using get Macro
Locate CsrLin + 2 : Color 7
Print "any user action --> EXIT!";
Sleep
Function mk64( ByVal lo As ULong, ByVal hi As ULong) As ULongInt
Asm ' works with FBC-WIN 32/64 (tested: ver. 1.05.0)
mov eax, dword Ptr [hi]
mov edx, dword Ptr [lo]
mov dword Ptr [Function], eax
mov dword Ptr [Function + 4], edx
End Asm
End Function